Template
You had seem generic when we talk about function.
type DbORM<DbT: type> (
DB: DbT
)
impl DbORM {
+connect(port_conf: str) {
self.DB.connect(port_conf)
}
+execute(sql: str) {
self.DB.execute(sql)
}
+close() {
self.DB.close()
}
}
If template at type, don't repeat it again.
You don't need to do that.
Specialize
impl DbORM<MySQL> {
// ...
}
What!? You just say don't do that! I heard.
Because write like this won't work like you think. It will specialize the DbORM this part's code.
When DbT != MySQL, this part code would not be impl.
impl DbORM<MySQL> {
+connect() { ... }
+execute(sql: str) { ... }
}
DbORM<SQLServer> do not have 'xxx'
So you need to realize, MySQL existed, or specialize won't be implemented.