M
Mateusz
Hi everyone
I have a design issue. I will try to explain it right now. Ask if
anything is unclear.
Let's say I want to make a coding DOM. User should be able to define
class or structure types. For this I have a class TypeDefinition and
two classes: StructureTypeDefinition, ClassTypeDefinition. These
classes are to be used for type defining.
The other thing user needs to be able to do is to define variables.
Each of these variables needs to have a type of course. So, for
defining variable I have created TypeReference class. This class has
an attribute called type: TypeDef which directs user to to the type of
the variable. This way I don't need to have a ClassTypeReference and
StructureTypeReference classes.
And I need TypeDefinition and TypeReference to output types in
different ways - first for defining it and second one for statements
like: var variableOfType of Type;
I have these classes at the moment:
TypeDefinition
StructureTypeDefinition: TypeDefinition
ClassTypeDefinition: TypeDefinition
TypeReference
+ type: TypeDefinition
Variable:
+ type: TypeReference
All was great. I'm lazy and I didn't have to create these
*TypeReference classes, so I was happy.
But (of course a "but" appears), now I came to a conclusion that
ClassTypeDefinition can inherit from some other class. So it needs an
attribute, e.g.: inheritance. This attribute is of type TypeRef.
Yet this is not perfect. User should only be able to create class
inheriting from other class and not StructureTypeDefinition. And here
is my problem.
How can I restrict user from create class which inherits from a
StructureTypeDefinition, yet not create whole ClassTypeReference and
StructureTypeReference hierarchy?
Now it is easy, I have two classes in this hierarchy. But later I
might have 50 definitions and I will need 50 references - which might
be a pain in the ass.
Do you know any pattern which I could/should use for this? I don't
want to copy all the classes.
Thanks
Mateusz
I have a design issue. I will try to explain it right now. Ask if
anything is unclear.
Let's say I want to make a coding DOM. User should be able to define
class or structure types. For this I have a class TypeDefinition and
two classes: StructureTypeDefinition, ClassTypeDefinition. These
classes are to be used for type defining.
The other thing user needs to be able to do is to define variables.
Each of these variables needs to have a type of course. So, for
defining variable I have created TypeReference class. This class has
an attribute called type: TypeDef which directs user to to the type of
the variable. This way I don't need to have a ClassTypeReference and
StructureTypeReference classes.
And I need TypeDefinition and TypeReference to output types in
different ways - first for defining it and second one for statements
like: var variableOfType of Type;
I have these classes at the moment:
TypeDefinition
StructureTypeDefinition: TypeDefinition
ClassTypeDefinition: TypeDefinition
TypeReference
+ type: TypeDefinition
Variable:
+ type: TypeReference
All was great. I'm lazy and I didn't have to create these
*TypeReference classes, so I was happy.
But (of course a "but" appears), now I came to a conclusion that
ClassTypeDefinition can inherit from some other class. So it needs an
attribute, e.g.: inheritance. This attribute is of type TypeRef.
Yet this is not perfect. User should only be able to create class
inheriting from other class and not StructureTypeDefinition. And here
is my problem.
How can I restrict user from create class which inherits from a
StructureTypeDefinition, yet not create whole ClassTypeReference and
StructureTypeReference hierarchy?
Now it is easy, I have two classes in this hierarchy. But later I
might have 50 definitions and I will need 50 references - which might
be a pain in the ass.
Do you know any pattern which I could/should use for this? I don't
want to copy all the classes.
Thanks
Mateusz