Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a scenario with 4 classes like,

class SuperGroup,
class Group,
class SubGroup,
class MicroGroup,

Here, SuperGroup will contain a list of Groups, and a Group will contain a list of SubGroups and so on...

Now, I want to design my classes in a way that, Groups can only be created by SuperGroups, and similarly SuperGroups could only create Groups, they cannot create SubGroups directly. Rather when they want a SubGroup, they have to create a Group, then by that object of Group, they could create subGroups.

The same conditions will also apply to < Group,SubGroups > , < SubGroups,MicroGroups > .

How could I achieve that in C#.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
188 views
Welcome To Ask or Share your Answers For Others

1 Answer

Perhaps you want createChild() to be a public method of each class, with the actual child constructors protected or private?

Client code would then call the parent entity to create child entities, rather than being able to construct them directly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...