0% found this document useful (0 votes)
87 views14 pages

Object Oriented Concepts & Principles

This document discusses key concepts and principles of object-oriented programming including objects, classes, encapsulation, inheritance, polymorphism, and more. It defines objects as complex data types that contain attributes and methods. Classes are templates used to create objects. Encapsulation hides attributes within objects to control access. Inheritance allows classes to inherit attributes and methods from more abstract classes in a hierarchy. Polymorphism means the same method can behave differently for different classes.

Uploaded by

Syed Zia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views14 pages

Object Oriented Concepts & Principles

This document discusses key concepts and principles of object-oriented programming including objects, classes, encapsulation, inheritance, polymorphism, and more. It defines objects as complex data types that contain attributes and methods. Classes are templates used to create objects. Encapsulation hides attributes within objects to control access. Inheritance allows classes to inherit attributes and methods from more abstract classes in a hierarchy. Polymorphism means the same method can behave differently for different classes.

Uploaded by

Syed Zia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Object Oriented Concepts &

Principles
Object Oriented Paradigm
(Paradigm: a way of seeing and doing things)
• Object - Oriented (OO) Programming:
– Organizing software as a collection of objects with a certain state
and behavior.
• Object Oriented Design:
– Based on the identification & organization of objects.
• OO Methodology
– Construction of models
– The development of SW is a modeling process
• OO Modeling and Design
– Modeling objects based on the real world
– Using models to design independently of a programming language
.
Objects
• Object: Complex data type that has an identity,
contains other data types called attributes and
modules of code called operations or methods
• Attributes and associated values are hidden inside
the object.
• Any object that wants to obtain or change a value
associated with other object, must do so by
sending a message to one of the objects (invoking
a method)
Objects
methods (methods)
Object: woman
Attributes (values)

method: Age: 35
Set_salary Salary: 10

Set_salary (20) Get_age

employer friend
Encapsulation
• Each objects methods manage it’s own attributes.
• This is also known as hiding.
• An object A can learn about the values of
attributes of another object B, only by invoking
the corresponding method (message) associated to
the object B.

• Example:
– Class: Lady
– Attributes: Age, salary
– Methods: get_age, set_salary
Procedural vs. Object-Oriented
Procedural application OO-application
DATA
Line of code Data is stored
Line of code independent
Line of code of application

Each object is independent of


the others
Classes
• Classes are templates that have methods and
attribute names and type information, but no
actual values!
• Objects are generated by these classes and they
actually contain values.
• We design an application at the class level.
• When the system is running objects are created by
classes as they are needed to contain state
information.
• When objects are no longer needed by the
application, they are eliminated.
Class & Objects
CLASS: Furniture
Name methods: Example
Number ChangeNumber

Objects:

Desk ChairA ChairB


123445 32143 45687
Message Passing & Associations
• Methods are associated with classes but classes
don’t send messages to each other.
• Objects send messages.
• A static diagram (class diagram) shows classes
and the logical associations between classes, it
doesn´t show the movement of messages.
• An association between two classes means that
the objects of the two classes can send messages to
each other.
• Aggregation: when an object contains other
objects ( a part-whole relationship)
Class Hierarchies & Inheritance
• Classes can be arranged in hierarchies so
that more classes inherit attributes and
methods from more abstract classes
• Class hierarchy diagrams
Class: Chair

subclasses

Chair Type A Chair Type B


Class Inheritance & Specialization
Class: Furniture
Class name Attribute A1 Attributes
Method A1
Methods
Class: Chairs
[Attribute A1]
Is a specialization of Attribute B1
[Method A1]
Or Method B1
Inherits from
Class: Executive Chairs
[Attribute A1]
[Attribute B1]
Attribute C1
[Method A1]
Method B1 (B1 code modified)
Method C1
Public, Private & Protected
• Attributes can be public or private:
– Private: it can only be accessed by its own methods
– Public: it can be modified by methods associated with
any class (violates encapsulation)
• Methods can be public, private or protected:
– Public: it’s name is exposed to other objects.
– Private: it can’t be accessed by other objects, only
internally
– Protected: (special case) only subclasses that descend
directly from a class that contains it, know and can use
this method.
Method signature
• It is the method’s name and the parameters
that must be passed with the message in
order for the method to function.
• The parameters are important because they
assure that the method will function
properly.
• Additionally they allow a compiler or
interpreter to discriminate between two
different methods with the same name.
Polimorphism
• Means that the same method will behave
differently when it is applied to the objects of
different classes
• It also means that different methods associated
with different classes can interpret the same
message in different ways.
• Example: an object can send a message PRINT to
several objects, and each one will use it’s own
PRINT method to execute the message.

You might also like