Is there a pattern...?

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
 
A

Alf P. Steinbach /Usenet

* Mateusz, on 08.07.2010 14:04:
I have a design issue. I will try to explain it right now. Ask if
anything is unclear.

Yeah, your question is extremely unclear.

It seems to relate to the design of a new C#-like language, not C++.

If there is a C++ question buried in there, please post a complete, minimal
example illustrating the problem. See the FAQ item about how to post questions.


[snip]

Cheers & hth.,

- Alf
 
M

Michael Doubez

* Mateusz, on 08.07.2010 14:04:


I have a design issue. I will try to explain it right now. Ask if
anything is unclear.

Yeah, your question is extremely unclear.

It seems to relate to the design of a new C#-like language, not C++.

If there is a C++ question buried in there, [snip]

I guess there is:
The OP asks for a pattern but I don't see where a pattern comes into
play.
A solution from my cristal ball is to provide only a const acces to
ClassTypeDefinition.inheritance and provide setInherintanceType that
restrict to ClassTypeDefinition input.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top