Professional Documents
Culture Documents
1
Object Oriented Programming
Object-oriented (OO) is a model organized around "objects" rather than "actions" and data rather
than logic. Historically, a program has been viewed as a logical procedure that takes input data,
processes it, and produces output data.
2
Object
3
A Class
Classes are templates for objects. They contain all the common properties
and behaviors of a group of objects.
All objects with the same attributes and behaviors belong to the same class.
All objects with the same attributes and behaviors belong to the same class.
Attributes - It is a data value that is held by object of a class. It has a unique name within
a class and should have a pure data value.
4
Objects vs classes
5
Inheritance
A class is a category of objects. An object is an instance of a class. As an instance of a
class, an object has all the characteristics of its class. This is called inheritance. Whatever
attributes and operations you decide on for the person class, each object in that class will
inherit those attributes and operations
6
Inheritance – Example
7
Data Encapsulation
When an object carries out its operations, those operations are hidden. This is the essence
of encapsulation.
An object hides what it does from other objects and from the outside world . this reason
encapsulation is also called as information hiding. But an object has to present a face to the
outside world so you can initiate those operations.
8
Message Passing
In a system objects work together. They do by sending messages to one another. One object
sends another a message to perform an operation, and the receiving object performs that
operation.
9
Associations (Relationships)
Associations is a symmetrical relationship between two classes which
specifies the manner in which objects belonging to the two classes are
related.
Following UML diagram illustrates that Course class associates with
Lecturer class, because we know Courses are taught by Lecturers.
10
Multiplicity (Cardinality)
It tells the number of objects in one class that is related to a single object of
the associated class.
01. One to One : Object in one class is related to one object of the associated class.
02. One-to-Many : Object in one class is related to many objects of the associated class.
03. Many-to-Many : Objects in one class are related to many objects of the associated class.
11
Aggregation
If you think about your computer system, it consists of several components such as CPU,
keyboard, mouse and etc. out of these components there are some elements you would
undoubtedly find it hard to live without.
Your computer is an aggregation, another kind of association among objects. Like many other
things worth having, the computer is made from a number of different types of components.
Computer
12
Composition
13
17
Polymorphism
Sometimes an operation has the same name in different classes. You can open a door,
you can open a window, and you can open a newspaper. In each case you are performing
a different operation. In OO each class “knows” how that operation is supposed to take
place. This is called polymorphism.
14
Lesson Summery
Object Oriented Programming
Object
Class
Inheritance
Associations
Cardinality of Associations
Aggregation vs Composition
15