Địa Chỉ: Km 26, Quốc lộ 1A, Phong An, Phong Điền, TT Huế | Hotline: 091 889 1512


Discover Connection, Constitution, Aggregation and Genetics in C#

Discover Connection, Constitution, Aggregation and Genetics in C#

In this article we are going to you will need to learn how to implement relationships in the c-sharp playing with object built principles such as genetics, association, aggregation and you may composition having a straightforward analogy and you can need having fun with c-sharp.

All these relationship is founded on “try a beneficial” matchmaking, “has-a” dating and you will “part-of” dating. Therefore allow me to define your this one by that.

Heredity predicated on Try-A relationship

Inheritance inside the C# is actually a pops-man matchmaking where i do a new classification by using existing category password (i.e. hookup Saskatoon reusing strategies, functions or other parameters). Genetics allows us to recycle of password again again means moms and dad category might be used to the level of child classes. Heredity spends special profile titled “:” colon and come up with a love.

In this over example the mother are an excellent PQRCompany. SalesManager is a member of staff performs in PQRCompany and you may SalesTeam will work from the PQRCompany.Generally there is actually a dad-man relationship between PQRCompany-SalesManager and you may PQRCompany-SalesTeam, since SalesManager and you may SalesTeam really works under same business. Today let put that it on programming layout.

In the place of using a buddies name while the a father you could potentially also use “employee” given that a parent group since the SalesManager and you can SalesTeam was each other team merely.However it is elective it will changes considering scenario in the event that need you can keep “Company” since a grandfather or “Employee” since a pops. Making this exactly how we have to use parent-child dating inside our password according to the condition.

Connection lies in Has-A romance

Organization is dependant on “has-a” relationship idea. I’d like to determine you the meaning having fun with a simple analogy. Imagine i have a couple different kinds Class1 and a great Class2 when these organizations share for every single anyone else object for some works at the same time frame they’re able to exists versus for every single anybody else dependancy (having their particular life) and there should not be any unmarried manager one another must be an independent out of one another next sorts of relationship known because “has-a” relationship we.e. Connection.

Within this example we’ll extract connection principle. SalesManager uses an employeecard to enter regarding organization. Right here we have to do a few groups “SalesManager” and you may “EmployeeCard” due to the fact SalesManager was a member of staff out of a pals and you may providers uses a keen employeecard so you can approve their employees so one another have to a other organizations and also at a same we would like to violate single responsibility concept setting we can’t provide employeecard group jobs in order to salesmanager category.

Solitary obligation idea claims that every classification must do their unique work such Membership group should do accounting really works and you can Staff category is always to care for personnel info.

When you see “SalesManager” classification using “EmployeeCard” target to test authorization procedure and you will “EmployeeCard” uses “SalesManager” target to check on if or not a member of staff try productive or not. Therefore one another agencies express each other people target for some work however, they’re not dependent on each other as we can play with same “EmployeeCard” target various other departments out of a buddies eg having “SalesTeam” class, “AccountTeam” group, “Staff” class and stuff like that along with in the same way “SalesManager” target may be used in numerous cities such as for example getting “SalesTeam” group, “ProductSales” group and the like.

Thus these organizations possess their own life from object and at same day they share each other people object getting specific works. 1st area is the fact there no proprietor one another entities try equal. Whilst the thing is i’ve successfully generated a link relationship.

Aggregation will be based upon Possess-A love

Aggregation would depend is on “has-a” matchmaking principle. Here each other entities satisfy for the majority of functions immediately after which get split up but right here you to organization should be a holder and at a same go out they must be independent from both (that have own life). Within the connection idea there is no owner however in aggregation one you to entity is a holder with other entity.

Within more than condition you will find two organizations “SalesManager” and you may “SalesTeam”. With regards to the real world circumstances “SalesManager” must be a holder to “SalesTeam” setting SalesManager only utilize the target of SalesTeam to show their group details and also at a same time SalesTeam has individual target lifetime form it is not dependent on SalesManager. SalesTeam can be placed less than BranchHead otherwise CompanyHead. very i would ike to put which regarding programming concept.

When you see inside our significantly more than code that SalesManager class spends SalesTeam object to show details away from his performing team. Here SalesManager category is an owner because spends SalesTeam target for some time as well as an exact same go out these two classes has independent of each almost every other. Which mode i have successfully generated a great aggregation dating.

If you have detailed i incorporate aggregation during the three-tier architecture form in business coating class i spends analysis covering classification object showing info that is where company covering could well be a proprietor of data coating. Making this including an enthusiastic aggregation relationships.

Structure will be based upon Area-Out of Dating – Death Matchmaking

Constitution was a good “part-of” dating. Contained in this dating both agencies are interdependent of each and every most other such as for example a human body lies in cardiovascular system and you may viceversa center was dependent on muscles borh is inadequate without each other.

In our over password we have one or two groups “SalesManager” and you can “clsProduct” respectively. As you may know overall conversion process-manager paycheck lies in equipment offering and you may tool promoting is actually in addition to influenced by conversion-movie director. Therefore they are both interdependent on every most other. In an identical way we generated a composition dating in which each other organizations lives day is based on each other.

When you see we can not load any points playing with “clsProduct” class because we require “SalesManager” target to check if one to “SalesManager” completed early in the day week address or otherwise not same manner “SalesManager” classification including cannot weight issues instead of “clsProduct” target and then we don’t write “LoadProducts()” strategy into the “SalesManager” since it often violate our unmarried obligation concept.Making this the way we enjoys successfully produced composition relationship.

So this is about matchmaking inside the target established coding. When you yourself have any second thoughts or ask please tell me via your beneficial remark whenever you adore this particular article kindly share with friends and family or associates. Thanks a lot.

Lắp đặt chuyên nghiệp
Đội ngũ lắp đặt, tư vấn kỹ thuật giàu kinh nghiệp
Giao nhận tiện lợi
Giao nhận trong ngày, cam kết đối đa 5h
Thanh toán linh hoạt
Phương thức thanh toán đa dạng tiện lợi
Đổi trả dễ dàng
Đổi sản phẩm kỹ thuật lỗi trong 30 ngày
Hậu mãi chu đáo
Tận tình chăm sóc khách hàng trong suốt dòng đời sản phẩm

Nhân Viên Hỗ Trợ (8h00 - 22h00)

Tổng đài mua hàng: 091.889.1512
Giao nhận - Bảo hành: 091.889.1512

Email: [email protected]
Trụ Sở Chính: - Km 26, Quốc lộ 1A, Phong An, Phong Điền, TT Huế


Hãy liên hệ với chúng tôi nếu bạn có thắc mắc về sản phẩm và dịch vụ!

    Phòng Kinh Doanh


    Hotline 2


    Would love your thoughts, please comment.x