![]() Let me explain you the definition using a simple example. So this is how we need to implement parent-child relationship in our code according to the scenario.Ĭlick here to know more on: Implementing inheritance in C#.Īssociation is based on HAS-A RelationshipĪssociation is based on "has-a" relationship principle. ![]() Instead of using a company name as a parent you can also use " employee" as a parent class because SalesManager and SalesTeam are both employees only.But it is optional it can change according to scenario if you need you can keep " Company" as a parent or " Employee" as a parent. SalesManager is an employee works in PQRCompany and SalesTeam are working in the PQRCompany.So there is a parent-child relationship between PQRCompany-SalesManager and PQRCompany-SalesTeam, because SalesManager and SalesTeam work under same company. In this above example our parent is a PQRCompany. SalesManager is an employee of PQRCompany.2. Inheritance uses special character called " :" colon to make a relationship.ġ. Inheritance allows us to reuse of the code again again means parent class can be implemented to any number of child classes. reusing methods, properties and other variables). Inheritance in C# is a parent-child relationship where we create a new class by using existing class code (i.e. SalesManager has got responsibility to sell the products and to achieve the monthly target.Īll these relationship is based on " is a" relationship, " has-a" relationship and " part-of" relationship. SalesManager has got SalesTeam to work under him.ĥ. SalesManager has an employeecard to enter into PQRCompany.Ĥ. ![]() SalesManager is an employee of PQRCompanyĢ. To make you understand about inheritance, association, aggregation and composition let me take up a real world scenario.ġ. In this article we will try to understand how to implement relationships in c-sharp using object oriented principles like inheritance, association, aggregation and composition with a simple example and explanation using c-sharp.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |