Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Chap.

fer 6
=
'<ii!!!! - - =;:,' - = -

Obiect-Oriented Concepts

Quick Chapter Summary


Object
t Object means Entities.
t In the "real" world, objects are the entities of which the
world is comprised.
t Object is divide in two parts :
(1) Concrete form: Person, car or a Coffee cup.
(2) Abstract form : Do not represent things which can be
touched or seen, Date and Time.
t All objects have unique identity and are distinguishable
from each other.
I i
Object
• Characteristics are known as properties or attributes.
• Every person has characteristics like name, city, gender.
tTo identify the object, we use the value of these attribute,
which called state.
• State is used distinguish objects from each other.
• Two persons have same name, they may be
distinguished using other attribute like birth-date.
• State of the object can change due to its behaviour, which
called as method also.
• Person takes birth, gets name, changes location.
[TI
• Real world object can be described in terms :

'---Hf) Ident ity What it is called ?


(2) State What it is?
(3) Behaviour What it does ?
• Attributes describe the object are referred to as data field.
• Data attribute & behavioral methods associated with an
object are collectively referred members or features.
•Example:
Railway : Train, Passenger, Ticket etc meaningful objects.
car, Computer, Watch may be irrelevant objects.

~
Object-oriented Programming
t Playing significant role in analysis, design and

implementation of software system.

t Concepts started originating in the 1960s.


t It had become the main programming paradigm used in
the creation of new software in the mid 1980s.

tSupports C++, Java, C#, VB.net, ASP.net, PHP.

co
Way of Programming
t Programming can be divided Into two categories :
~ ) Structure/ Procedural Programming
• The focus is on writing functions or procedures.
• Ex: Library- Stud. registration, book issue, return etc.
(2) Object-oriented Programming
• The focus Is on objects, which contain both data and
functionality together.
• Ex : Library - Student, Book, Library
• Object is fundamental building block in Object-oriented.
IT]
Object-oriented - Properties
t A computer language is object-oriented if they supports
below four specific object properties :
(1) Abstraction
(2) Encapsulation
(3) Polymorphism
(4) Inheritance
t Object-oriented programming uses object as its
fundamental building block.
Class
t Class can be considered as a blueprint for various objects.
t It is a template for multiple objects with similar features.
t Class is general concept used to embody all the common
features of a particular set of objects.
t It describes a group of...o.bjects with similar attributes and
common behaviour.
t Objects in the same class share a common semantic
purpose.
Example: Class Person
Object Name, Citv, Gender, Birthdate
O:J
Class Diagram
tThe purpose of the class diagram is to model the static
view of an application.
t Class diagram are the only diagrams which can be directly
mapped with object oriented language.
t Unified Modeling Language (UML) can be used to create
models of object-oriented software.
t UML is a visual modeling language.
t It defined and maintained by Object Management Group (OMG).
[TI
Class Diagram - Representation
t Class diagram, a class is represented with an icon using a
rectangle split into three sections :

~ !Name Top section Name of the class


Attribute or Properties of
(2) Attribute Middle section
the class
Behaviour or Operations
(3) Behaviour Bottom section
or Methods of the class
Class diagram - Visibility feature
t In class diagram, visibility represent using four symbols :
(1) Private

(2)

(3) Public +

(4) Package -
Enapsulation
tThe mechanism of providing protection t o data and
methods of a program is called Encapsulation. -
t Encapsulation provides data hiding capability.
t Encapsulation keeps the data safe from unintended
actions and inadvertent access by outside objects.
t Computer program, two core elements are data & functions.
t Structured/Procedural programming views these two core
elements as two separate entities.
tObject-oriented programming views them as single entity.
[!!]
Data Abstraction
t Data abstraction is a process of representing the es~

--
details. -
features of the objects without including implementation

tAbstraction is a concept t hat hides the complexity.


t It says what it does, but not how it is done.
tExample :
• Abstract Data Type (ADT) or Structures in C/C++
t It enables to represent data in which the implementation
details are hidden.
Polymorg_bjsm
t Polymorphism means~ -

t There may be different forms of single metb._od or~ on.

tThe capability of using same names to mean different

---
things in different contexts is called overloadi'!&,._

• Polymorphism is achieved using two types of overloading :

{1) Function overloading

(2) Operator overloading


Aggregation and Composition
t When objects of one class are composed of objects of
other class, it is called aggregation or composition.

-
t It represents 'has-a' or 'a-part-of relationship between classes.
Example :

~ erboard is a part of computer.

~ puter is composed of many parts like motherboard,


screen, keyboard and mouse.

Du
Aggregation v/s Composition
t Aggregation represents non-exclusive relationship.
t Motherboard is part of the computer; it can exist as a
separate item independent of the computer.
t If address object may be shared by two or more persons,
so address is not exclusive to any one person.
t Composition represents exclusive relationship.
tExample :
Name is associated exclusively with single person.
Inheritance
t Inheritance referred to a elationship.
t It is appropriate when one class is 'a-kind-of other class.
tExample :
• Teacher is a kind of person.
• All attribute and methods of class 'Person' are
applicable to class 'Teacher' also.
t New class is called as sub class, child class or derived class.
t Existing class is called as super class, parent class or base
class.

You might also like