DCO10105 Object-Oriented Programming and Design - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

DCO10105 Object-Oriented Programming and Design

Description:

Rossella Lau Lecture 6, DCO10105, Semester B,2005-6 ... above class diagram, it uses navigability arrow to represent the relationship ... – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 23
Provided by: rossel
Category:

less

Transcript and Presenter's Notes

Title: DCO10105 Object-Oriented Programming and Design


1
DCO10105 Object-Oriented Programming and Design
  • Lecture 6 More on class construction
    UML and an introduction to inheritance
  • More on class construction
  • Multiple inclusion
  • Use of accessor and mutator
  • Function overload and signature
  • Members of pointer
  • The resolution operator and namespace
  • UML and an introduction to inheritance
  • UML Class diagram
  • Some class diagrams in the real world
  • Some class diagrams for typical applications
  • -- By Rossella Lau

2
Revisit IntArray.h IntArray.cpp
  • inndef _INT_ARRAY_Hdefine
    _INT_ARRAY_H......endif
  • These are pre-processor statements to avoid
    multiple inclusion
  • The pre-processor uses a symbol _INT_ARRAY_H to
    indicate that the body within inndef -- endif,
    including _INT_ARRAY_H, will be defined if it is
    not defined yet
  • When the same header file is included the second
    time, since it is already defined, the body will
    not be included

3
The dynamic array -- pointer
  • The dynamic array array actually is a pointer
  • Its main purpose is to get dynamic memory
    allocation for the array
  • However, whenever you have a pointer variable, it
    complicates the constructors and destructors and
    usually you must define your own rather than
    using those generated by the compiler
  • In other words, for simple classes such as
    clockType and Qudratic, we can use the compiler
    generated constructors and destructors

4
The identifier starting with _
  • Identifiers of data members in IntArray start
    with _ (an underscore)
  • Traditionally, C defines system (library
    functions) variables with a prefix _ to avoid
    conflict with programmer defined variable names

5
Use of accessor and mutator
  • Although a member can access any other members in
    a class, it is a good habit to use accessor and
    mutator in service functions and use mutator to
    set the value for the data in the constructor if
    the respective data does have a domain checking
    and maintaining in the mutator e.g.,
    DateType.cpp
  • I.e., Data members are usually only directly
    referenced in constructors, accessors, and
    mutators recheck IntArray.cpp Quadratic.cpp

6
Function overload
  • Several constructor ids and identical function
    ids can exist in the same class or the same
    program
  • IntArray(int), IntArray(IntArray const )
  • fillData(double,size_t), fillData(int,size_t)
  • Same function ids with different signatures are
    allowed in modern languages
  • Return type parameters of a function are the
    functions signature
  • When a function call is encountered, the compiler
    checks the type(s) of its parameter(s), the
    signature, and finds the function with such
    signature to call

7
and namespace
  • identifies a member of a class (. identifies a
    member of an object)
  • can also identify members in namespace
  • Namespace Maliks slide 818-23
  • ?Same symbol but different application
  • You cannot use using namespace IntArray to save
    the typing of IntArray for the function
    implementation in IntArray.cpp

8
UML
  • Unified Modeling Language
  • Software blueprint language
  • Similar to blueprints, standard graphical
    language, for the architects and builders
  • There are nine kinds of modeling diagrams
  • Use Case diagrams, Class diagrams, Object
    diagrams, Sequence diagrams, Collaboration
    diagrams, Statechart diagrams, Activity diagrams,
    Component diagrams, and Deployment diagrams
  • Reference www.borland.com

9
Class diagram
  • It gives an overview of a system by showing the
    relationships among them
  • Association relationship between instances of
    two classes
  • It is a link in a diagram
  • Aggregation an association in which one class
    belongs to a collection
  • It is a link with a diamond end pointing to the
    part containing the whole
  • Generation indicating inheritance between
    classes
  • It is a link with a triangle end pointing to the
    base class from sub classes

10
Navigation and multiplicity
  • In the above class diagram, it uses navigability
    arrow to represent the relationship rather than
    the standard
  • It shows which direction the association can be
    traversed
  • Multiplicity shows the possible instances for an
    aggregation e.g.,
  • An order has at least one order item
  • A catalog has zero or many products

11
An example customer orders
  • http//bdn.borland.com/article/0,1410,31863,00.htm
    lclassdiagrams

12
Class notation
  • A 3-piece rectangle E.g., Maliks Figure 12-1

13
Visibility and scope
  • http//bdn.borland.com/article/images/31863/classd
    iagram.html

14
Introduction to inheritance
  • A sub class has the attributes and properties
    (operations) of its base class
  • A sub class inherits everything from its base
    class in OO view all the data members and
    function members
  • It is quite similar to class taxonomy or class
    classification in the real world
  • Animals can be classified as mammal, bird, fish
    there are different kinds of mammals man, pet,
    wild animal, farm animal, whale, etc

15
Real world example CityU
16
Real world example Animal
17
Application The shapes
18
Application Course management
19
A class diagram for gourmetCoffee
20
Other typical applications
  • A restaurant system
  • A retail system
  • A course management system
  • A library system
  • A payroll system

21
Summary
  • In this class, we revisited class construction
    with some related concepts and techniques
    pre-processors supports, pointer member and
    class, good programming practice in using
    accessor and mutator, and namespace
  • The class diagram of the UML helps in modeling a
    system
  • The class diagram also introduces the
    relationship of inheritance

22
Reference
  • Malik 8.3, 12.1.1, 13
  • http//bdn.borland.com/article/0,1410,31863,00.htm
    l
  • -- END --
Write a Comment
User Comments (0)
About PowerShow.com