Oop Basics
-
Upload
niyasahamed3 -
Category
Documents
-
view
93 -
download
1
Transcript of Oop Basics
![Page 1: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/1.jpg)
1
Object Oriented ProgrammingDevelopment
By: Marc ConradUniversity of Luton
Email: [email protected]: D104
![Page 2: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/2.jpg)
2
What are we doing today?
Introduction of: the lecturer Objects Basic Terminology C++ the module
![Page 3: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/3.jpg)
3
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 4: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/4.jpg)
4
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 5: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/5.jpg)
5
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 6: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/6.jpg)
6
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 7: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/7.jpg)
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 8: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/8.jpg)
8
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 9: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/9.jpg)
9
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 10: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/10.jpg)
10
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 11: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/11.jpg)
11
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 12: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/12.jpg)
12
Basic Terminology:Aggregation
Aggregation describes a “has a” relationship. One object is a part of another object.
We distinguish between composite aggregation (the composite “owns” the part) and shared aggregation (the part is shared by more then one composite).
A car has wheels.
![Page 13: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/13.jpg)
13
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 14: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/14.jpg)
14
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 15: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/15.jpg)
15
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 16: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/16.jpg)
16
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 17: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/17.jpg)
17
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 18: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/18.jpg)
18
Module Outline
IntroductionThe non object
oriented basicsClassesDesign ApproachesTesting
InheritanceAggregationPolymorphismMultifile
Development
![Page 19: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/19.jpg)
19
Assessment Details
50% in course and 50% exam.For more details for the in course
assignment see separate handout.
![Page 20: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/20.jpg)
20
Books
Teach Yourself C++ in 10 minutes,J. Liberty, SAMS 1999.
C++ - How to program, Deitel & Deitel, Prentice Hall, 2001.
Object Oriented Programming with C++, David Parson, Letts Educational, London 1997.
![Page 21: Oop Basics](https://reader030.fdocuments.net/reader030/viewer/2022012318/5477f8595806b5e8188b46b2/html5/thumbnails/21.jpg)
21
Websites
A C++ online tutorial:http://www.cplusplus.com/doc/tutorial/
The C++ FAQ:http://www.parashift.com/c++-faq-lite
The homepage of Bjarne Stroustrup, the inventor of C++:http://www.research.att.com/~bs
And many, many more!