Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
What are the difference between Composition and Aggregation in C#?
Under Composition, if the parent object is deleted, then the child object also loses its status. The composition is a special type of Aggregation and gives a part-of relationship.
For example, A Car has an engine. If the car is destroyed, the engine is destroyed as well.
public class Engine {
. . .
}
public class Car {
Engine eng = new Engine();
.......
}
Aggregation is a directional relation between objects in C#. It is the relationship between objects.
For example, Employee and Address
An Employee is associated with a single Department, whereas a Department can have more than one employee. Let us see an example of Employee and Address −
public class Address {
. . .
}
public class Employee {
private Address addr;
public Employee (Address addr) {
this.addr = addr;
}
. . .
} Advertisements
