Top Banner
OBJECT ORIENTED PROGRAMMING M Taimoor Khan [email protected]
24
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

OBJECT ORIENTED PROGRAMMINGM Taimoor Khan

[email protected]

Page 2: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

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.

Page 3: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

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

Page 4: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

Course Outline

Classes Polymorphism Encapsulation Operators overloading Method overriding Templates Inheritance Types of classes

Page 5: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

Marks Distribution

Criteria %age

1st Sessional 10%

2nd Sessional 15%

Assignments 10%

Quizes 15%

Final Exam 50%

Page 6: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

Course Flow

Key concepts Quick Revision Class practice Notes

Resource www.cstags.com Labs

Lab Instructor Mr. Waqas Ahmed

Page 7: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

Course Textbook(s)

Object Oriented Programming in C++ 4th Edition by Robert Lafore

How to Program in C++ 7th Edition by Deitel n Deitel

Page 8: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

Object Oriented Programming An approach to application development Appropriate for large scale applications

with teams of developers OO Programming paradigm: collection of

objects

Page 9: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

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

OOAD

Page 10: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

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

OOA

Page 11: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

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

OOD

Page 12: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

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)

Page 13: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

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

Page 14: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

The evolution of OOP

Global Variables Life time spans program execution

Local Variables Life time limited to execution of a specific routine

Instance variables Posses data of an object

Static Variables Visible in single scope

Modules Allow several subroutines to share a set of static variables

Module Types Multiple instances of an abstraction

Classes Families of related abstraction

Page 15: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

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 development can be done by more

than one person

Page 16: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

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++

Page 17: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

Benefits of OOP

Promote code reuse Reduces code maintenance Simplifies extending applications

Page 18: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

Methods

Functions still do the work in OO But now they

Just know what they need to know Generally contain less code

Page 19: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

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

Page 20: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

Initialization and Finalization of Objects

Choosing a constructor How are constructors supported in the

language Execution order of initialization

E.g with derived classes Garbage collection

Destructors

Page 21: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

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

Page 22: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

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

Page 23: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

Inheritance

Defines subclasses Creates ‘is a’ relationship

E.g Nokia is a cell phone Resuse common functionality

Specialization Extend or override common functionality

for specific needs

Page 24: OBJECT ORIENTED PROGRAMMING M Taimoor Khan taimoorkhan@ciit-attock.edu.pk.

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