I created a base library/package containing the class Type
and its childs ObjectType
and PrimitiveType
.
In addition to that, I have 3 different use cases for this type classes that logically belongs to other packages.
- Render a data type into a generated class (parameter or return type), e.g.
toCode()
=>?int = 3
- Render a data type into the documentation, e.g.
toDoc()
=>int|null
- Convert a data type of the programming language to a database type, e.g.
toDatabaseType()
=>TINYINT(1)
Of course I want to use the base package without dependencies to the "generator" or "ORM" package.
I also would like to use any combination of all 3 packages.
How would you implement this?
Duplicating the object hierarchy in every package will prevent a mixed usage.
A Decorator
Mixins etc. and AOP are not supported. And extending the class at runtime
will lose any type safety.
I'm getting closer to the point thinking that a switch
per package is the cleaner approach assuming that there will be "no" new Type
s in the future.
Aucun commentaire:
Enregistrer un commentaire