Class design 'dilemma' -
I have never designed a proper class, so bear with me.
Let's say we have the project
class. So suppose we have a project group
class, which has members like project
class, as well as of project
s
Project Group
Project
or Project Group
Project
should be specialization and prior Should be a subclass of the latter?
I will not bother you with the theory , because you get quick answers Are in a hurry. So here it goes:
If your two classes are actually mentioned then they should be related to heritage, then from project group
to project
class Should get. How would it be like the C #:
the public class looks like a project group: Project ... if they are not, but they belong to some common class Uses members (which defines their state and some functionality in that situation), I will write an interface and apply it in both classes. C # code again: public interface ICMMST ... Public Sector Project: ICMMS Tate ... public class project group: Aiseedomenstet {Aianmumerebl & lt; ICMMSTAT & gt; Projects ...}
Edit
If your classes are actually project
and project groups
and They have both in common (for example) such as id
and names
, they should not be inherited yet. They have qualities with the same name, but they are basically different bodies.
They can implement a ICommonEntity
interface - it is used when they have the same status + functionality, But the functionality behaves differently in each of them
General Entity - The functionality is completely identical when using it; Then your component can be an interface or a square (using the overall pattern).
The direct fortune between two classes is more suitable, where the institutions give signals to be related to each other. Like the user
and person
classes. They may in any way be deprived, depending on the business scenario.
class user: person
This will be the situation where you have an application with contacts, some of them are users of the same application.
class person: user
This will be a web site where you can register as a user. If you fill out some personal details then your user data type becomes person
.
Comments
Post a Comment