0% found this document useful (0 votes)
13 views

UML Association, Aggregation, Composition

Uploaded by

deysoham16
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

UML Association, Aggregation, Composition

Uploaded by

deysoham16
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Object Oriented Concept

• Class is a detailed description, the definition, and the template of


what an object will be. But it is not the object itself. Also, what we
call, a class is the building block that leads to Object-Oriented
Programming. It is a user-defined data type, that holds its own data
members and member functions, which can be accessed and used by
creating an instance of that class. It is the blueprint of any object.
Once we have written a class and defined it, we can use it to create as
many objects based on that class as we want. In Java, the class
contains fields, constructors, and methods.
• For example, consider the Class of Accounts. There may be many
accounts with different names and types, but all of them will share
some common properties, as all of them will have some common
attributes like balance, account holder name, etc. So here,
the Account is the class.
• Object is an instance of a class. All data members and member
functions of the class can be accessed with the help of objects. When
a class is defined, no memory is allocated, but memory is allocated
when it is instantiated (i.e. an object is created). For Example,
considering the objects for the class Account are SBI Account, ICICI
account, etc.
Abstraction
• Data abstraction is one of the most essential and important
features of object-oriented programming .

• Abstraction is a process of hiding irrelevant details from


user.
• For example, When you send an sms you just type the
message, select the contact and click send, the phone
shows you that the message has been sent, what actually
happens in background when you click send is hidden from
you this is called data hinding or abstraction.

• In OOP, we use abstract class and interface to achieve


abstraction.
Encapsulation
• In normal terms, Encapsulation is defined as wrapping up of data
and information under a single unit. In Object-Oriented
Programming, Encapsulation is defined as binding together the
data and the functions that manipulate them.
• So Encapsulation is placing the data and the functions that work on
that data in the same place. While working with procedural
languages, it is not always clear which functions work on which
variables but object-oriented programming provides you
framework to place the data and the relevant functions together in
the same object.
Example
• Consider a real-life example of encapsulation, in a company, there are different
sections like the accounts section, finance section, sales section etc. The finance
section handles all the financial transactions and keeps records of all the data
related to finance. Similarly, the sales section handles all the sales-related
activities and keeps records of all the sales. Now there may arise a situation
when for some reason an official from the finance section needs all the data
about sales in a particular month. In this case, he is not allowed to directly access
the data of the sales section. He will first have to contact some other officer in
the sales section and then request him to give the particular data. This is what
encapsulation is. Here the data of the sales section and the employees that can
manipulate them are wrapped under a single name “sales section”.
• Encapsulation also leads to data abstraction or hiding. As using encapsulation
also hides the data. In the above example, the data of any of the section like
sales, finance or accounts are hidden from any other section.
Polymorphism
• The word polymorphism means having many forms. In simple words, we can define
polymorphism as the ability of a message to be displayed in more than one form.
• A person at the same time can have different characteristic. Like a man at the same time is a
father, a husband, an employee. So the same person posses different behaviour in different
situations. This is called polymorphism.
• An operation may exhibit different behaviours in different instances. The behaviour depends
upon the types of data used in the operation.

• Operator Overloading: The process of making an operator to exhibit different behaviours in


different instances is known as operator overloading.
• Function Overloading: Function overloading is using a single function name to perform
different types of tasks.
Polymorphism is extensively used in implementing inheritance.
Inheritance
• The capability of a class to derive properties and characteristics from
another class is called Inheritance. Inheritance is one of the most
important features of Object-Oriented Programming.
• Sub Class: The class that inherits properties from another class is called
Sub class or Derived Class.
• Super Class:The class whose properties are inherited by sub class is called
Base Class or Super class.
• Reusability: Inheritance supports the concept of “reusability”, i.e. when we
want to create a new class and there is already a class that includes some
of the code that we want, we can derive our new class from the existing
class. By doing this, we are reusing the fields and methods of the existing
class.
UML Association vs. Aggregation vs. Composition

• In UML diagrams, relationships are used to link several things. It is a


connection between structural, behavioral, or grouping things.
Following are the standard UML relationships enlisted below:
• Association
• Dependency
• Generalization
• Realization
• Association
• Association relationship is a structural relationship in which different
objects are linked within the system.
• It exhibits a binary relationship between the objects representing an
activity. It depicts the relationship between objects, such as a teacher,
can be associated with multiple teachers.
• It is represented by a line between the classes followed by an arrow
that navigates the direction, and when the arrow is on both sides, it is
then called a bidirectional association. We can specify the multiplicity
of an association by adding the adornments on the line that will
denote the association.
1) A single teacher has multiple students.

2) A single student can associate with many teachers.


• The composition and aggregation are two subsets of association. In
both of the cases, the object of one class is owned by the object of
another class; the only difference is that in composition, the child
does not exist independently of its parent, whereas in aggregation,
the child is not dependent on its parent i.e., standalone. An
aggregation is a special form of association, and composition is the
special form of aggregation.
• Aggregation
• Aggregation is a subset of association, is a collection of different
things. It represents has a relationship. It is more specific than an
association. It describes a part-whole or part-of relationship. It is a
binary association, i.e., it only involves two classes. It is a kind of
relationship in which the child is independent of its parent.
• For example:

• Here we are considering a car and a wheel example. A car cannot


move without a wheel. But the wheel can be independently used
with the bike, scooter, cycle, or any other vehicle. The wheel object
can exist without the car object, which proves to be an aggregation
relationship.
• Composition
• The composition is a part of aggregation, and it portrays the whole-
part relationship. It depicts dependency between a composite
(parent) and its parts (children), which means that if the composite is
discarded, so will its parts get deleted. It exists between similar
objects.

• As you can see from the example given below, the composition
association relationship connects the Person class with Brain class,
Heart class, and Legs class. If the person is destroyed, the brain,
heart, and legs will also get discarded.
Association vs. Aggregation vs. Compositi
Association Aggregation Composition

Association relationship is represented using an arrow. Aggregation relationship is represented by a straight line with an empty diamond at one end. The composition relationship is represented by a straight line with a black diamond at one end.

In UML, it can exist between two or more classes. It is a part of the association relationship. It is a part of the aggregation relationship.

It incorporates one-to-one, one-to-many, many-to-one, and many-to-many association between It exhibits a kind of weak relationship. It exhibits a strong type of relationship.
the classes.

It can associate one more objects together. In an aggregation relationship, the associated objects exist independently within the scope of In a composition relationship, the associated objects cannot exist independently within the
the system. scope of the system.

In this, objects are linked together. In this, the linked objects are independent of each other. Here the linked objects are dependent on each other.

It may or may not affect the other associated element if one element is deleted. Deleting one element in the aggregation relationship does not affect other associated It affects the other element if one of its associated element is deleted.
elements.

Example: A tutor can associate with multiple students, or one student can associate with Example: A car needs a wheel for its proper functioning, but it may not require the same wheel. Example: If a file is placed in a folder and that is folder is deleted. The file residing inside that
multiple teachers. It may function with another wheel as well. folder will also get deleted at the time of folder deletion.

You might also like