1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic...

29
1 Object Oriented Programming Development

Transcript of 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic...

Page 1: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

1

Object Oriented ProgrammingDevelopment

Page 2: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

Introduction of: the lecturer Objects Basic Terminology C++ the module

What are we doing today?

Page 3: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

PROGRAMMING PARADIGMS

A Programming Paradigms defines the Methodology of designing and implementing programs using the key feature and building blocks of a Programming Language .

Types1. Procedural Programming2. Object Based Programming3. Object Oriented Programming

Page 4: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

Procedural Programming

A Program in a procedural language is a list of instruction where each statements tells the computer to do something. The focus is on the Processing, the Algorithm needed to perform the desired computation.

Page 5: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

Object Based Programming

In this programming data and its associated meaningful function as enclosed in one single entity a class. Classes enforce information hiding and abstraction thereby separating the implementation details & uses the interface.

Page 6: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

Object Oriented Programming

This programming paradigm is support of object based programming. It offers all the features of object based programming and overcomes its limitations by implementing inheritance so that real world relations among objects can be represented programmatically.

Page 7: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

7

What is Object Oriented Programming?

An object is like a black box.

The internal details are hidden.

Identifying objects and assigning responsibilities to these objects.

Objects communicate to other objects by sending messages.

Messages are received by the methods of an object

Page 8: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

8

What is an object?

Tangible Things as a car, printer, ...Roles as employee, boss, ...Incidents as flight, overflow, ...Interactions as contract, sale, ...Specifications as colour, shape, …

Page 9: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

9

So, what are objects?

an object represents an individual, identifiable item, unit, or entity, either real or abstract, with a well-defined role in the problem domain.

OrAn "object" is anything to which a

concept applies. Etc.

Page 10: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

10

Why do we care about objects?

Modularity - large software projects can be split up in smaller pieces.

Reuseability - Programs can be assembled from pre-written software components.

Extensibility - New software components can be written or developed from existing ones.

Page 11: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

Example: The Person class#include<string>#include<iostream>class Person{ char name[20]; int yearOfBirth;public: void displayDetails() { cout << name << " born in " << yearOfBirth << endl; } //...};

private data

public processes

Page 12: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

12

The two parts of an object

Object = Data + Methods or to say the same differently:

An object has the responsibility to know and the responsibility to do.

= +

Page 13: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

13

Basic Terminology

Abstraction is the representation of the essential features of an object. These are ‘encapsulated’ into an abstract data type.

Encapsulation is the practice of including in an object everything it needs hidden from other objects. The internal state is usually not accessible by other objects.

Page 14: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

14

Basic Terminology:Inheritance

Inheritance means that one class inherits the characteristics of another class.This is also called a “is a” relationship:

A car is a vehicle

A teacher is a person

A dog is an animal

Page 15: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

15

2. Inheritance Concepts

Derive a new class (subclass ) from an existing class ( base class or superclas

s).

Inheritance creates a hierarchy of rela ted classes (types) which share code a

nd interface.

Page 16: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

IIIIIIIIIII IIIIIIII

Base Class Derived Classes

Student CommuterStudentResidentStudent

Shape CircleTriangleRectangle

Loan CarLoanHomeImprovementLoanMortgageLoan

Page 17: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

Types of Inheritance

Single Multiple Multilevel Hierarchical Hybrid

Page 18: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

18

Basic Terminology:Polymorphism

Polymorphism means “having many forms”. It allows different objects to respond to the same message in different ways, the response specific to the type of the object.E.g. the message displayDetails() of the Person class should give different results when send to a Student object (e.g. the enrolment number).

Page 19: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

Types of Polymorphism

Compile time/ Static Polymorphism Function Overloading Run time/ Dynamic Polymorphism Virtual Function Operator Overloading

Page 20: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

20

Basic Terminology:Modularity

Modularity is the property of a system that has been decomposed into a set of cohesive and loosely coupled modules

For example the computer system comprises CPU, Monitor, Keyboard , Mouse & Speakers etc. Now these parts are complete unit in themselves, yet they are a subpart of computer. This is Modularity .

Page 21: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

21

Basic Terminology:Behaviour and Messages

The most important aspect of an object is its behaviour (the things it can do). A behaviour is initiated by sending a message to the object (usually by calling a method).

Page 22: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

22

The two steps of Object Oriented Programming

Making Classes: Creating, extending or reusing abstract data types.

Making Objects interact: Creating objects from abstract data types and defining their relationships.

Page 23: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

23

Historical NotesC++ owes most to C.

Other ancestors are Simula67and Algol68.

First versions of C++ in 1980 under the name “C with classes”. Since 1983 the name C++ is used.

1990: ANSI/ISO 9899 defines a standard for C

1998: ISO/IEC 14882 specifies the standard for C++

C++ 1987

Page 24: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

24

C++ and C

C is a subset of C++.Advantages: Existing C libraries can be used, efficient code can be generated.But: C++ has the same caveats and problems as C (e.g. pointer arithmetic,…).

C++ can be used both as a low level and as a high level language.

We focus on the

high level

aspects.

Page 25: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

25

C++ and Java

Java is a full object oriented language, all code has to go into classes.

C++ - in contrast - is a hybrid language, capable both of functional and object oriented programming.

So, C++ is more powerful but also more difficult to handle than Java.

Page 26: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

Advantages of OOPs

Re use of Code It model real world well Program are easy to understand Easy redesign & Extension

Page 27: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

Disadvantages of OOPs

The relations among classes become artificial as times

The OOPs Program’s design is tricky. To program with OOP, Programmer

proper Skil.

Page 28: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

28

Module Outline

IntroductionThe non object

oriented basicsClassesDesign ApproachesTesting

InheritanceAggregationPolymorphismMultifile

Development

Page 29: 1 Object Oriented Programming Development. zIntroduction of: ythe lecturer yObjects yBasic Terminology yC++ ythe module What are we doing today?

Thank You