Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Suppose i have a class say Student it has two sub classes as a part-whole relationship called Student Address and Student Marks, I want to apply a composite pattern for this by defining a common interface for all the sub classes, I call this interface IStudent. But my problem is: 1) if i just take the abstract properties and create an interface i cannot access the details of the sub classes means IStudent=new StudentAddress() wont give me access to all the Student address details only those that have been declared in I student. Also the Student marks class is totally different so the same interface wont hold. How do I apply composite patterns to this??:confused:
Posted

1 solution

You will be able to use Composite pattern for Student and StudentList:List<student> classes for that these classes will implement IStudent interface. Composite pattern vanishes the boundary between collections and items.
 
Share this answer
 
Comments
SreeniTheGinie 6-Oct-10 22:51pm    
Thank you for your answer Pavel. Does this mean the composite pattern cannot be implemented to no recursive hierarchies of classes. Is there a pattern that can be used in my situation?
Pavel Yermalovich 7-Oct-10 3:02am    
Can you give me more detailed description of your task? Describe your domain and general goals and i'll try to help you.
Pavel Yermalovich 7-Oct-10 3:16am    
To store information about marks you can create the property of List type in Student class and for student address you will create the property too. I don't understand why you want to apply this pattern for student details. I see just one case. And this is the situation when your class will have f.e. two properties for addresses and marks that will be collections and you want to implement IComposite interface for these collections to carry out CRUD operations.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900