Object Oriented Programming

Download Report

Transcript Object Oriented Programming

OBJECT ORIENTED
PROGRAMMING
M Taimoor Khan
[email protected]
Course Description
It teaches the concepts of object-oriented
programming. Topics include data abstraction,
encapsulation, hierarchy via composition and
derivation (inheritance), and polymorphism. C++
used for lab work. A computer science major that
makes the basis of programming applications.
Course Relevance
This course is of key importance to advance to
programming as a profession. It gives all the
important concepts and practical experience of the
programming language. It can be extended to
learning other languages like Java, PHP C# etc by
using the same knowledge in different syntax
Course Outline








Classes
Polymorphism
Encapsulation
Operators overloading
Method overriding
Templates
Inheritance
Types of classes
Marks Distribution
Criteria
%age
1st Sessional
10%
2nd Sessional
15%
Assignments
10%
Quizes
15%
Final Exam
50%
Course Flow




Key concepts
Quick Revision
Class practice
Notes
 Resource

www.cstags.com
Labs
 Lab
Instructor Mr. Waqas Ahmed
Course Textbook(s)


Object Oriented Programming in C++ 4th Edition
by Robert Lafore
How to Program in C++ 7th Edition by Deitel n
Deitel
Object Oriented Programming



An approach to application development
Appropriate for large scale applications with teams
of developers
OO Programming paradigm: collection of objects
OOAD





The proverb “owning a hammer doesn’t make one an
architect” is especially true with respect to object
technology
Knowing an object language is necessary but insufficient
to create object systems
Its about analyzing system requirements in terms of
objects and allocating responsibilities to class objects
How would these objects collaborate with each other
What classes should do what
OOA




It emphasizes on finding requirements and problems
rather than solutions
Object oriented analysis is a process of analyzing
requirements in an object oriented paradigm
It approves some of the requirements while discards
others
Based on this OOA the OOD is built
OOD




It emphasizes on the conceptual solution in software
or hardware that fulfills the requirements
It does not give any implementation details
Design ideas normally exclude low level details that
are obvious to the intended customers
Ultimately designs can be implemented in code to
give its true and complete realization
How to solve OOP problem






Identify nouns, they are your potential objects
(Discard irrelevant ones)
Identify adjectives, they are your potential
attributes (Discard irrelevant ones)
Identify verbs, they are your potential behaviors
(Discard irrelevant ones)
What is irrelevant!
Classes (Object types)
Map classes (Communication channels)
Case study

A system is required that will allow users to login
through their valid name and password. Users will
have to register first to use the system. Users will be
required to make their profile with their personal
data as first name, last name, date of birth and city.
Users should be able to add other users as friends.
Users can send messages to their friends
The evolution of OOP

Global Variables


Local Variables


Allow several subroutines to share a set of static variables
Module Types


Visible in single scope
Modules


Posses data of an object
Static Variables


Life time limited to execution of a specific routine
Instance variables


Life time spans program execution
Multiple instances of an abstraction
Classes

Families of related abstraction
Why OOP


Reduces conceptual load by reducing amount of
detail
Provides fault containment
 Can’t

use components e.g (class ) in inappropriate ways
Provides independence between components
 Design
person
development can be done by more than one
Keys to OOP


An instance of a class is called object
Languages that are based on classes are called
object oriented languages
 For
example C++
 Java
 Microsoft .NET framework languages C#, VC++
Benefits of OOP



Promote code reuse
Reduces code maintenance
Simplifies extending applications
Methods


Functions still do the work in OO
But now they
 Just
know what they need to know
 Generally contain less code
Keys to OO Programming

Encapsulation (Data Hiding)
 Enable
programmer to group data and subroutines
(methods) together, hiding irrelevant details from users

Inheritance
 Enables
a new abstraction ie a derived class to be
defined as an extension of an existing abstraction,
retaining key characteristics

Dynamic data binding
 Enabling
use of new abstraction i.e derived classes to
exhibit new behavior in context of old abstraction
Initialization and Finalization of
Objects

Choosing a constructor
 How

Execution order of initialization
 E.g

are constructors supported in the language
with derived classes
Garbage collection
 Destructors
Classes and objects

Objects are actors in your application
 Refers

to individual pieces of data
A class define the data and behavior of object
 Objects
in your application are instances of a class
Objects

An object is a thing
 More
precisely an object is the representation of a
thing
 Has characteristics
 We
call these attributes or properties
 Properties are just variables rebranded
 Those things which the object has
 Has
behavior
 We
call these methods
 Methods are just functions rebranded
 Those things which the object does
Inheritance


Defines subclasses
Creates ‘is a’ relationship
 E.g
Nokia is a cell phone
 Resuse common functionality

Specialization
 Extend
needs
or override common functionality for specific
Encapsulation

Treat each object as a black box
 Well
defined interface of data and methods
 Must use this interface in the application


All data is private
Methods can be public, private or protected