Kinh doanh:
0912 189 489See Relationship, Structure, Aggregation and you may Inheritance inside the C#
In this article we are going to attempt to can apply matchmaking for the c-clear playing with target depending standards eg inheritance, association, aggregation and you will composition with an easy example and reasons playing with c-sharp.
Many of these matchmaking is founded on “are a beneficial” dating, “has-a” dating and “part-of” relationships. Thus i want to define you this 1 of the one.
Mục lục
Inheritance centered on Is-A love
Genetics within the C# are a dad-guy relationships in which i carry out a different class by using present classification password (i.elizabeth. reusing actions, features or any other variables). Genetics lets us recycle of your password again once more function mother class would be accompanied to any amount of man categories. Inheritance spends special reputation titled “:” anus while making a love.
Inside a lot more than example all of our father or mother is a PQRCompany. SalesManager was a member of staff really works into the PQRCompany and you may SalesTeam are working regarding PQRCompany.So there try a dad-son dating ranging from PQRCompany-SalesManager and you can PQRCompany-SalesTeam, due to the fact SalesManager and you may SalesTeam works significantly less than same company. Today let place so it about programming layout.
Instead of using a family name just like the a parent you might additionally use “employee” as the a dad class due to the fact SalesManager and you can SalesTeam is actually each other professionals simply.However it is elective it will transform based on circumstances when the you prefer you can keep “Company” as the a pops or “Employee” because the a dad. Making this how we need use father or mother-child dating within code depending on the situation.
Connection is founded on Possess-A love
Association is dependent on “has-a” matchmaking idea. I’d like to identify the meaning using an easy example. Think i’ve one or two various other categories Class1 and you may a beneficial Class2 whenever those two organizations show for each someone else target for the majority of works as well as the same time frame they are able to is obtainable as opposed to each other people dependancy (having their particular life time) there should be no unmarried proprietor each other have to be an independent off both upcoming sorts of matchmaking known since “has-a” relationships we.e. Relationship.
Contained in this example pÅ™Ãklady profilů christianconnection we are going to pull organization concept. SalesManager uses an enthusiastic employeecard to get in on team. Here we need to carry out two groups “SalesManager” and you will “EmployeeCard” as SalesManager try an employee away from a family and you can providers uses an employeecard to approve their employees thus each other need an effective additional entities and also at a same we should break solitary obligation concept function we can’t promote employeecard group jobs so you can salesmanager classification.
Unmarried responsibility idea says that each and every classification have to do their own jobs such Account class must do accounting functions and you may Staff member class is manage personnel details.
Once you see “SalesManager” group having fun with “EmployeeCard” target to evaluate agreement processes and “EmployeeCard” spends “SalesManager” object to check whether a member of staff are active or otherwise not. Thus both agencies share for every single other people object for the majority of performs however, they are certainly not influenced by both since we could fool around with exact same “EmployeeCard” object in other divisions off a friends particularly getting “SalesTeam” group, “AccountTeam” classification, “Staff” category and stuff like that as well as in the same exact way “SalesManager” object can be utilized in various urban centers including to have “SalesTeam” classification, “ProductSales” classification and so on.
Very those two entities has actually her life out of object and also at same time it show for each and every other people target having certain works. The very first region is the fact truth be told there no single owner both entities try equal. So as you notice you will find successfully made an association relationship.
Aggregation will be based upon Provides-A relationship
Aggregation depends is found on “has-a” relationships concept. Here one another entities see for some works and rating separated but here you to definitely organization must be a holder as well as an exact same day they must be separate away from one another (having individual lifetime). Into the relationship concept there is absolutely no proprietor however in aggregation any one to organization are going to be a holder some other organization.
Contained in this a lot more than situation we have several entities “SalesManager” and “SalesTeam”. According to real world condition “SalesManager” must be a proprietor so you can “SalesTeam” mode SalesManager is only going to use the object off SalesTeam showing his people facts and at a same big date SalesTeam enjoys individual target life time means this is simply not influenced by SalesManager. SalesTeam may be placed significantly less than BranchHead or CompanyHead. so i want to set which regarding coding layout.
If you see within a lot more than password you to definitely SalesManager classification spends SalesTeam object to exhibit suggestions out of their operating party. Here SalesManager group are a proprietor because it uses SalesTeam object for a while as well as an exact same go out these two classes has separate of each and every almost every other. That it function i have properly produced a aggregation relationships.
If you have detailed we use aggregation during the three-tier frameworks function running a business covering group we spends study level category object to exhibit records and here team layer would-be an owner of information layer. So this is and additionally a keen aggregation relationship.
Structure lies in Part-Out-of Dating – Passing Dating
Structure are a great “part-of” matchmaking. Within this relationships both entities was interdependent of each and every other such as for instance a system is dependent on center and you may viceversa cardio is dependent on human body borh try useless as opposed to one another.
In our significantly more than password i have several groups “SalesManager” and you can “clsProduct” respectively. As we know typically transformation-movie director salary lies in equipment offering and you can product attempting to sell was plus dependent on sales-manager. Therefore they are both interdependent for each almost every other. Same way we produced a layout relationship in which both entities existence time is dependant on one another.
When you see we cannot weight any factors having fun with “clsProduct” category once the we are in need of “SalesManager” object to check if you to definitely “SalesManager” accomplished earlier in the day week target or perhaps not in an identical way “SalesManager” classification including don’t load situations instead of “clsProduct” target so we try not to make “LoadProducts()” approach in the “SalesManager” since it have a tendency to violate all of our unmarried obligation concept.So this is how exactly we has efficiently made constitution relationship.
Making this all about matchmaking into the target centered programming. When you yourself have any doubts otherwise query be sure to tell me via your valuable remark assuming you adore this informative article kindly share with your friends otherwise colleagues. Many thanks.