Top Banner

of 20

oopweek1

Apr 08, 2018

Download

Documents

rnyambati
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
  • 8/7/2019 oopweek1

    1/20

    1

    Object Oriented Programming

    Development

  • 8/7/2019 oopweek1

    2/20

    2

    What is Object Oriented

    Programming?

    An object is like ablack box.

    The internaldetails arehidden.

    Identifying objects andassigning responsibilities to

    these objects. Objects communicate to

    other objects by sendingmessages.

    Messages are received bythe methods of an object

  • 8/7/2019 oopweek1

    3/20

    3

    What is an object?

    Tangible Things as a car, printer, ...

    Roles as

    Incidents as flight,

    Interactions as contract, sa

    Specifications as colour, shape,

  • 8/7/2019 oopweek1

    4/20

    4

    So, what are objects?

    an object represents an individual,identifiable item, unit, or entity, either

    real or abstract, with a well-defined rolein the problem domain.

    Or

    An "object" is anything to which aconcept applies.

    Etc.

  • 8/7/2019 oopweek1

    5/20

    5

    Why do we care about

    objects?

    Modularity - large software projectscan be split up in smaller pieces.

    Reuseability - Programs can beassembled from pre-written softwarecomponents.

    Extensibility - New softwarecomponents can be written ordeveloped from existing ones.

  • 8/7/2019 oopweek1

    6/20

    Example: The Person class

    #include

    #include

    class Person{

    char name[20];

    int yearOfBirth;public:

    void displayDetails() {

    cout

  • 8/7/2019 oopweek1

    7/20

    7

    The two parts of an object

    Object = Data + Methods

    or to say the same differently:

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

    = +

  • 8/7/2019 oopweek1

    8/20

    Basic Terminology

    Abstraction is the representation of theessential 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 usuallynot accessible by other objects.

  • 8/7/2019 oopweek1

    9/20

    Basic Terminology:

    Inheritance

    Inheritance means that one class inheritsthe 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

  • 8/7/2019 oopweek1

    10/20

    10

    Basic Terminology:

    Polymorphism

    Polymorphism means having manyforms. It allows different objects to

    respond to the same message in differentways, the response specific to the type ofthe object.

    E.g. the message displayDetails() of thePerson class should give different resultswhen send to a Student object (e.g. theenrolment number).

  • 8/7/2019 oopweek1

    11/20

    11

    Basic Terminology:

    Aggregation

    Aggregation describes a has arelationship. One object is a part of

    another object.

    We distinguish between composite

    aggregation (the composite owns thepart) and shared aggregation (the part is

    shared by more then one composite).

    A car has wheels.

  • 8/7/2019 oopweek1

    12/20

    12

    Basic Terminology:

    Behaviour and Messages

    The most important aspect of an object isits behaviour (the things it can do). A

    behaviour is initiated by sending amessage to the object (usually by callinga method).

  • 8/7/2019 oopweek1

    13/20

    13

    The two steps of Object

    Oriented Programming

    MakingClasses: Creating, extendingorreusingabstract datatypes.

    MakingObjectsinteract: Creatingobjectsfrom abstract datatypesand defining

    their relationships.

  • 8/7/2019 oopweek1

    14/20

    14

    Historical Notes

    C++ owes most to C.Other ancestors are Simula67and Algol68.

    First versions ofC++ in 1980 under thename C with classes. Since 1983 thename C++ is used.

    1990: ANSI/ISO 9899 defines a standardfor C

    1998: ISO/IEC 14882 specifies the

    standard for C++

    C++ 1987

  • 8/7/2019 oopweek1

    15/20

    15

    C++ and C

    C is a subset ofC++.Advantages: ExistingC libraries canbe

    used, efficient code canbe generated.But: C++ has the same caveats andproblems as C (e.g. pointer arithmetic,).

    C++ canbe usedboth as a low level andas a high level language.

  • 8/7/2019 oopweek1

    16/20

    16

    C++ and Java

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

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

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

  • 8/7/2019 oopweek1

    17/20

    17

    Module Outline

    Introduction

    The non object

    oriented basics Classes

    Design Approaches

    Testing

    Inheritance

    Aggregation

    Polymorphism Multifile Development

  • 8/7/2019 oopweek1

    18/20

    18

    Assessment Details

    50% in course and 50% exam.

    For more details for the in course

    assignment see separate handout.

  • 8/7/2019 oopweek1

    19/20

    19

    Books

    Teach YourselfC++ in 10 minutes,J. Liberty, SAMS 1999.

    C++ - How to program, Deitel & Deitel,Prentice Hall, 2001.

    Object OrientedProgramming with C++,

    DavidParson, Letts Educational, London1997.

  • 8/7/2019 oopweek1

    20/20

    20

    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 ofC++:http://www.research.att.com/~bs