MENUMENU
Know Relationship, Structure, Aggregation and you can Inheritance within the C#
On this page we’ll you will need to can use relationship into the c-clear playing with target oriented prices such genetics, connection, aggregation and structure having an easy example and you can need having fun with c-sharp.
All these relationships will be based upon “are good” relationship, “has-a” relationships and you will “part-of” relationships. Therefore allow me to describe your this by the you to definitely.
Inheritance during the C# try a daddy-man dating in which i would a different category by using current category code (we.elizabeth. recycling methods, qualities or other variables). Inheritance allows us to recycle of your own password once again once more means mother category would be observed to your amount of boy categories. Genetics uses special character called “:” anus and then make a love.
Within this a lot more than example our mother was an excellent PQRCompany. SalesManager is a member of staff work during the PQRCompany and you may SalesTeam are working regarding PQRCompany.Generally there are a dad-boy relationship ranging from PQRCompany-SalesManager and PQRCompany-SalesTeam, as the SalesManager and you may SalesTeam really works around same team. Now assist place it regarding the coding build.
Unlike having fun with a company label because the a grandfather you could potentially additionally use “employee” just like the a daddy classification since SalesManager and you can SalesTeam was one another teams just.But it is optional it will transform based on situation if you need you can keep “Company” while the a father otherwise “Employee” because the a father. So this is how we need to apply mother or father-guy matchmaking inside our password with respect to the condition.
Organization lies in “has-a” relationships idea. I want to describe you the definition playing with an easy example. Think i have one or two various other classes Class1 and you can good Class2 when those two entities display for every single someone else target for many work as well as the same time they could is present in the place of per anyone else dependancy (that have their particular life) so there should not be any single holder each other need to be an independent off one another upcoming kind of matchmaking is well known once the “has-a” relationship we.elizabeth. Relationship.
Inside analogy we will extract association concept. SalesManager uses an employeecard to go into from the team. Right here we should instead carry out two categories “SalesManager” and you may “EmployeeCard” once the SalesManager is actually a member of staff out of a pals and providers spends an enthusiastic employeecard to authorize their employees therefore one another have to a beneficial additional organizations and at a same we need to break unmarried responsibility concept mode we can’t promote employeecard category occupations to help you salesmanager class.
Unmarried duty concept states that each and every group have to do their work such as for instance Membership class want to do accounting performs and Staff classification should take care of employee facts.
Once you see “SalesManager” category using “EmployeeCard” target to test agreement techniques and “EmployeeCard” spends “SalesManager” target to evaluate if an employee was effective or perhaps not. So each other organizations share for each others object for most performs however, they’re not influenced by one another because we can have fun with same “EmployeeCard” target various other departments of a friends for example to own “SalesTeam” classification, “AccountTeam” class, “Staff” classification and stuff like that along with in the same way “SalesManager” object can be utilized in almost any towns and cities like to possess “SalesTeam” group, “ProductSales” category and so on.
Thus these agencies has their own life time regarding target as well as exact same go out it share for each and every anybody else object for some performs. 1st area is that around not one manager each other agencies was equivalent. Whilst you notice i’ve successfully produced a link relationships.
Aggregation depends is found on “has-a” matchmaking idea. Right here both agencies see for some works and score split up however, right here one entity must be a proprietor and at a same date they ought to be separate out-of each other (which have individual life time). Into the association concept there is no owner but in aggregation any that organization will be a holder to other entity.
Within above situation we have two entities “SalesManager” and you may “SalesTeam”. According to the real world circumstances “SalesManager” has to be a manager in order to “SalesTeam” setting SalesManager simply utilize the target regarding SalesTeam showing their team ideas and at an exact same date SalesTeam features individual object life time form it is not influenced by SalesManager. SalesTeam can be placed less than BranchHead otherwise CompanyHead. therefore i’d like to put this on the coding design.
If you see within our more than password one to SalesManager classification uses SalesTeam object to demonstrate info regarding his working cluster. Right here SalesManager class try a manager because it uses SalesTeam target for some time as well as an exact same go out those two classes enjoys separate of each almost every other. Which setting i have effectively produced good aggregation matchmaking.
When you yourself have detailed i pertain aggregation when you look at the datingranking.net local hookup Seattle WA three-tier frameworks means in business covering classification we uses data coating classification object to show ideas this is how team covering would-be an owner of data level. So this is and an aggregation matchmaking.
Constitution try a great “part-of” matchmaking. Inside relationships both agencies is actually interdependent of each most other eg a human anatomy is based on heart and viceversa heart was influenced by system borh is ineffective instead one another.
Within more than password i have a couple of categories “SalesManager” and you will “clsProduct” correspondingly. As you may know as a whole conversion process-manager salary will be based upon device promoting and you can equipment attempting to sell was and dependent on sales-movie director. Very they are both interdependent for each other. Same way we made a theme dating in which each other organizations existence time is founded on each other.
When you see we cannot load any points having fun with “clsProduct” class as we truly need “SalesManager” object to check if or not you to definitely “SalesManager” accomplished earlier month address or not same manner “SalesManager” class plus you should never weight activities rather than “clsProduct” target and then we you should never produce “LoadProducts()” method when you look at the “SalesManager” because it will break our very own solitary obligations principle.So this is how we keeps properly generated structure relationships.
So this is everything about relationships in target established coding. For those who have people doubts or query kindly tell me during your worthwhile review incase you like this informative article be sure to share with friends otherwise associates. Thank you so much.
Đăng nhập
Đăng ký
SEARCH
Chưa có bình luận. Sao bạn không là người đầu tiên bình luận nhỉ?