introduction to object orientation[1]
TRANSCRIPT
-
8/8/2019 Introduction to Object Orientation[1]
1/31
INTRODUCTIONINTRODUCTIONTO OBJECTTO OBJECTORIENTATIONORIENTATION
-
8/8/2019 Introduction to Object Orientation[1]
2/31
Overview Software Development life cycle
"Programming in the Small" and "Programming in
the Large" Object Orientation
An Object Model
Objects
Classes
Inheritance
Polymorphism
Object-Oriented Design: Finding Classes and
Operations
-
8/8/2019 Introduction to Object Orientation[1]
3/31
Definitions Object Oriented Programming (OOP is a
programming method that combines data and
instructions into a self-sufficient "object". "Object orientation provides a new paradigm for
software construction. In this new paradigm,
objects and classes are the building blocks, while
methods, messages and inheritance produce the
primary mechanisms".- Ann L. Winbald, Samuel D.
Edwards and David R. King in the book, "Object
Oriented Software".
-
8/8/2019 Introduction to Object Orientation[1]
4/31
Definitions In an object-oriented program, objects
represent the design. Objects have two
sections, fields (instance variables) andmethods. Fields represent what an object is.Methods represent how an object is used.These fields and methods are closely tied to
the real world characteristics and use of theobject. An object is used by means of itsmethods. The following figure shows a viewof object oriented programming
-
8/8/2019 Introduction to Object Orientation[1]
5/31
Definitions
-
8/8/2019 Introduction to Object Orientation[1]
6/31
Software Development Life
Cycle (SDLC)
ANALYSIS
MAINTENTANCE
IMPLEMENTATION
DESIGN
-
8/8/2019 Introduction to Object Orientation[1]
7/31
"Programming in the Small" and
"Programming in the Large"
Programming in the small
Programs are developed by a single programmer/small group of programmers.
All aspects of the project can be understood by a
single individual.
The major problem is the development of the
algorithms and data structures needed to solve
the task at hand.
-
8/8/2019 Introduction to Object Orientation[1]
8/31
"Programming in the Small" and
"Programming in the Large"
Programming in the large
The software system is developed by a largeteam of programmers, often with considerablespecialization.
No single individual can (likely) understand all
aspects of the project. The major problem is the coordination of the
diverse aspects of the project--people andsoftware systems
-
8/8/2019 Introduction to Object Orientation[1]
9/31
Object Orientation
Assumptions:
Describing large, complex systems as interacting objectsmake them easier to understandthan otherwise.
The behaviors of real world objects tend to be stable
over time.
The different kinds of real world objects tend to be
stable. (That is, new kinds appear slowly; old kinds
disappear slowly.)
Changes tend to be localizedto a few objects.
-
8/8/2019 Introduction to Object Orientation[1]
10/31
An Object Model
Our object model includes four components:
objects (i.e., abstract data structures)
classes (i.e., abstract data types)
inheritance (hierarchical relationships amongADTs)
polymorphism by inheritance Encapsulation
Abstraction
-
8/8/2019 Introduction to Object Orientation[1]
11/31
Objects
An objectis a separately identifiable entity that hasa set of operations and a state that records the
effects of the operations. That is, an object isessentially the same as an abstract data structure aswe have discussed previously.
Objects are characterized by:
state,
operations,
identity.
-
8/8/2019 Introduction to Object Orientation[1]
12/31
Classes A class is a template for creating objects.
A class describes a collection of related objects (i.e.,instances of the classes).
Objects of the same class have common operations and acommon set of possible states.
The concept of class is closely related to the concept ofabstract data type that we discussed previously. Rem: Abstract data type is a collection of data and a set of
operations on that data A data structure is a construct within a programming language
the stores a collection of data
A class description includes definitions of
operations on objects of the class,
the possible set of states.
-
8/8/2019 Introduction to Object Orientation[1]
13/31
Inheritance
A class D inherits from class B if D's objects form a
subset of B's objects.
Class D's objects must support all of the class B's
operations (but perhaps are carried out in a special way).
Class D may support additional operations and an
extended state (i.e., more information fields).
Class D is called a subclass or a childorderived class.
Class B is called a superclass or a parentorbase class.
-
8/8/2019 Introduction to Object Orientation[1]
14/31
Polymorphism
The concept of polymorphism (literally "manyforms")
Polymorphism appears in several forms.
Overloading(orad hoc polymorphism)
Parametric polymorphism
denotes the use of parameterized type (or class)definitions.
Polymorphism by inheritance (sometimes calledpure polymorphism .
-
8/8/2019 Introduction to Object Orientation[1]
15/31
Encapsulation
Encapsulation a way of packaging
information. Encapsulation allows the programmer to present clearly specified
interfaces around the services they provide.
The programmer can decide what should be
hidden and what is intended to be visible.
-
8/8/2019 Introduction to Object Orientation[1]
16/31
Abstraction
Abstraction refers to the act of representingessential features without including the background
details or explanations. It is the art of concentratingon the essential and ignoring the non-essential.Classes that use the concept of data abstraction areknown as "abstract data types". Abstract data types
are achieved by making certain variables andmethods in a class private.
-
8/8/2019 Introduction to Object Orientation[1]
17/31
Object-Oriented Design:
Finding Classes and Operations
The goals of the design phase are to:
yIdentify the classes. (What kinds of objects do
we have?)
y Identify the functionality of each class. What
does each kind of object do
y Identify the relationships among the classes.Does one kind of object use another in some
way? Is it a special case of another kind?
-
8/8/2019 Introduction to Object Orientation[1]
18/31
Object-Oriented Design:
Finding Classes and Operations
Example
y Computerized Telephone Book
As an example, consider a computerized telephone bookfor a university. The telephone book should containentries for each person in the university community--student, professor, and staff member. Users of the
directory can look up entries. In addition, theadministrator of the telephone book can, after supplyinga password, insert new entries, delete existing entries,modify existing entries, print the telephone book, and
print a listing of all students or of all faculty.
-
8/8/2019 Introduction to Object Orientation[1]
19/31
Object-Oriented Design:
Finding Classes and Operations
1.Identify the candidate classes. List the nouns and
noun phrases from the specification:
computerized telephone book, university, telephone
book, entry, person, university community, student,
professor, staff member, employee, user,
administrator, passwordOthers implicit : name, address, menu, collection of
address
-
8/8/2019 Introduction to Object Orientation[1]
20/31
Object-Oriented Design:
Finding Classes and Operations
2.Identify the candidate operations. List the
verbs from the specification.lookup entry, supply password, insert newentry, delete existing entry, modi fy existingentry, print telephone book, pr int all
students, print all employees, set telephonenumber f ield, get telephone number f ield,compare entries.
-
8/8/2019 Introduction to Object Orientation[1]
21/31
Object-Oriented Design:
Finding Classes and Operations
3. Eliminate unnecessary and synonym classes
and operations.
For example, computerized telephone book, telephone
book, and directory can be combined into a singlePhoneBook class. Similarly, entry and person can
be combined into a single Person class. Inaddition, all the print operations probably probablybe combined into a single print operation with
the differing functionalities specified by parameters
-
8/8/2019 Introduction to Object Orientation[1]
22/31
Object-Oriented Design:
Finding Classes and Operations
4.Associate the operations with the
appropriate classes.For example, associate lookup, insert,
delete, and modify entry operations with
the PhoneBook class, associate compare,
setPhoneNumber and
getPhoneNumber with the Person class,
etc.
-
8/8/2019 Introduction to Object Orientation[1]
23/31
Object-Oriented Design: Finding
Relationships Among Classes
The three relationships that are common are:
y use or awareness (uses),y aggregation or containment (has-a),
y inheritance or specialization (is-a).
-
8/8/2019 Introduction to Object Orientation[1]
24/31
-
8/8/2019 Introduction to Object Orientation[1]
25/31
Why is OOP Popular?
y OOP is revolutionary idea, totally unlikeanything that has come before programming
y OOP is an evolutionary step, followingnaturally on the heel of earlier programmingabstractions.
y People hoped that it would quickly and easilylead to increased productivity and improved
reliability - solve software crises
y People hoped for easy transition from existinglanguages
y Resonant similarity to techniques of thinkingabout problems in other domains.
-
8/8/2019 Introduction to Object Orientation[1]
26/31
Design Issues for OOPLs
The Exclusivity of Objects
Are Subclasses Subtypes?
Implementation and Interface Inheritance
Type Checking and Polymorphism
Single and Multiple Inheritance
Allocation and Deallocation of Objects
Dynamic and Static Binding
-
8/8/2019 Introduction to Object Orientation[1]
27/31
Objects Vs. Objects
#include
#include
class employee
{
char Fname[15],Mname[15],EMPID[6];
char Married[2];// Either Yes or NO
int age;
float Bsalary;
public:
void getdetails(); // function to get the epmloyees details
void showdetails();
float newsalary();
};
-
8/8/2019 Introduction to Object Orientation[1]
28/31
Objects Vs. Objects
void employee::getdetails()// function get details of the general employee
{
coutFname;coutMname;
coutage;
coutMarried;
coutBsalary;
}
-
8/8/2019 Introduction to Object Orientation[1]
29/31
Objects
void employee::showdetails() {
cout
-
8/8/2019 Introduction to Object Orientation[1]
30/31
Objects Vs. Objects
//The Driver Program void main()
{
employee E;
E.getdetails();
cout
-
8/8/2019 Introduction to Object Orientation[1]
31/31
Inheritance hierarchy
STUDENT
UNDERGRADUATE POSTGRADUATE
FULL TIME PART TIME