Learning Center
Plans & pricing Sign in
Sign Out
Your Federal Quarterly Tax Payments are due April 15th Get Help Now >>

Chapter02-Object Oriented Design Using UML2.0


									BCS 2143

 Object Oriented Design Using
   Objects Interactions
   Finding Classes
   Relationship Between Classes
   Attribute and Operation
   Class Diagram
   Name the basic components of object-oriented design using
   Experience with significant diagram in UML
   Experience with main part of class that consists of attributes
    and operation
   Class Diagram; association, aggregation and inheritance
   Basic concepts in Sequence Diagram
   Utilize all modeling concepts in solving problem
Unified Modeling Language
       UML - standardized general-purpose
        modeling language in the field of software
        engineering using graphical notations
       UML Diagrams:
         Use Case Diagram
         Class Diagram
         Interaction Diagram
         Component Diagram
         Etc.
           UML 2.0

                                                                  Emphasizes the
                                                                  dynamic behavior of
                                                                  the system by
  Emphasizes the static structure of the                          showing
  system using objects, attributes,                               collaborations
  operations and relationships                                    among objects and
                                                                  changes to the
                                                                  internal states of
UML 2.0 has 13 types of diagrams divided into three categories. Six diagram types
represent the structure application, seven represent general types of behavior,
including four that represent different aspects of interactions.
Use Case Diagram
   System behavior – how the system act
    and react towards their environment.
   Consists of:
       Actor – represent environment of system

       Use case – represent function of system
  Example of Use Case Diagram
  for ATM Machine

Customer        Make transaction

             Manage bank transaction
Bank Clerk                             Bank

                 Produce report

              Maintain ATM Machine
Class Diagram
   Diagram that consists of several classes or
   Object :
       represent specific entity in term of physical and
       have the behaviors, characteristics and identity
   Class :
       Represent a group of object that have the similar
        attribute, behavior and relationship among the others
Example of Class Diagram
   Class diagram: describes the structure
    of a system by showing the system's
    classes, their attributes, and the
    relationships among the classes.
Interaction Diagram
Represent string of messages that
  have been submit and receive and
  its relation
 Example of 2 types:
     Sequence diagram – based on
      sequence of time frame
     Collaboration diagram – represent the
      data flow
Sequence Diagram
 Collaboration Diagram
                                        2: Enter current semester
                  1: Enter ID

                                                                               Registration Windows

                                3: Create new timetable
                                                                                  4: Display

: Johan:Student                                           Timetable

                                                           5: Get the course

                                Course Offered
Classes and Objects
   Object-oriented programs use objects.
   An object is a thing, both tangible and
    intangible. Account, Vehicle, Employee, etc.
   To create an object inside the computer
    program, we must provide a definition for
    objects—how they behave and what kinds of
    information they maintain —called a class.
   An object is called an instance of a class.
Graphical Representation of a

           <Class Name>
                            We use a rectangle to
                            represent a class with
                            its name appearing
                            inside the rectangle.

Example:     Account      Motorcycle
Graphical Representation of an
                           We use a rectangle to
                           represent an object
                           and place the
           <Object Name>   underlined name of the
                           object inside the


                            This is an object
                            named PersonA.
An Object with the Class

                                   This notation indicates
    <Object Name> : <Class Name>   the class which the
                                   object is an instance.


                                    This tells an object
                                    PersonA is an instance
          PersonA : BankAccount
                                    of the BankAccount
Messages and Methods
   To instruct a class or an object to perform a task,
    we send a message to it.
   A class or an object must possess a matching
    method to be able to handle the received message.
   A method defined for a class is called a class
    method, and a method defined for an object is
    called an instance method.
   A value we pass to an object when sending a
    message is called an argument of the message.
 Sending a Message
  Message deposit with
  the argument 250.00 is
  sent to a BankAccount
  object PersonA.

                                               PersonA : BankAccount

Examples              personA.deposit( 250.0 );
                      car1.startEngine( );
  Sending a Message and
  Getting an Answer
Ask for the current
balance of this
particular account.

                                                     PersonA : BankAccount

                           current balance

                                     The current balance of
                                     PersonA is returned.
Calling a Class Method

Ask for the maximum
possible speed for all
MobileRobot objects is


                             maximum speed
Class and Instance Data
   An object is comprised of data values and methods.
   An instance data value is used to maintain information
    specific to individual instances. For example, each
    BankAccount object maintains its balance.
   A class data value is used to maintain information
    shared by all instances or aggregate information about
    the instances.
   For example, minimum balance is the information
    shared by all Account objects, whereas the average
    balance of all BankAccount objects is an aggregate
Sample Instance Data Value
  Ali : BankAccount       Ani : BankAccount        Siti : BankAccount

   current balance         current balance           current balance
       908.55                 1304.98                   354.00

          All three BankAccount
                                              The actual dollar
          objects possess the
                                              amounts are, of course,
          same instance data
          value current balance.
       Sample Class Data Value
                         BankAccount                  There is one copy of
                                                      minimum balance
                         minimum balance              for the whole class
                                                      and shared by all
                               100.00                 instances.

This line is an

    Ali : BankAccount    Ani : BankAccount   Siti : BankAccount

       current balance     current balance     current balance
           908.55             1304.98              354.00
Object Icon with Class Data
     Ali : BankAccount

      minimum balance    When the class icon is
            100.00       not shown, we include
                         the class data value in
       current balance   the object icon itself.
   Class name
       Start with capital letter for each new word
       Example : Student, StudentAdvisory
   Attributes
       Represent the characteristics of the object
       Variables,
   Operation
       Represent the behavior of the class
       Methods, behaviors
                      Student                  Class

                        age                  Attribute
                      course                 (variable)


             Object                 Object
StdDiploma                                    Std1
    Java Code : Class, Attribute,
    Method Declaration

public class Student {   // class name
      String name;    // attribute @ variable
      int age =10;
      String course = “DCS” ;
      double fees = 1067.60;

     public void registerSubject (){
               // code for register subject
       Java Code :
       Object Declaration /
public Class Student{

       public static void main (String data[]){
           Student stdDiploma ; // declaring/creating an object
           stdDiploma = new Student() ; // object initialize
           Student Std1 = new Student() ; // declaration and
  = " Amad“ ; // assigning value to object
           Std1.age = 24 ; // assigning value to object
           System.out.println(" student name : " + ;
           System.out.println(" student age registration : " +
                              Std1.age) ;

Relationships among Classes
   Association
   Aggregation
   Composition
   Inheritance
      Association represents a general binary relationship
      that describes an activity between two classes.
                          Take                                    Teach
                  5..60                                    0..3                     1
        Student                            * Course                            Teacher

public class Student {           public class Course {               public class Faculty {
  /** Data fields */               /** Data fields */                  /** Data fields */
  private Course[]                 private Student[]                   private Course[]
    courseList;                      classList;                          courseList;
                                   private Faculty faculty;
    /** Constructors */                                                   /** Constructors */
    /** Methods */                   /** Constructors */                  /** Methods */
}                                    /** Methods */                  }

     An association is usually represented as a data field in the class.
   Whole-to-part associations
 The concept representing the whole is
  called the aggregate; each concept
  representing a part is called constituent.
 The aggregate and the constituent may

  existed independently of each other.
Example of Aggregation
                    Student Club

          1 ... *                  1 ... *

      1                                      1 ... *

     Advisor                          Member
   Whole-to-part associations
   The concept representing the whole is called
    the composite; each concept representing a
    part is called component
   The composite does not exist independently
    from its component
   The component may exist without the
    Example of Composition


1         1                 1         2

Frame      Back           Seat   Arm Rest
  Aggregation vs Composition
                     AGGREGATION          COMPOSITION
Name of whole      Aggregate            Composite
Name of part       Constituent          Component
Parts              May be different     Usually the same
                   types                type
Existence          May exist without    Does not exist
                   its parts            without its parts
Number of wholes   Part may belong to   Part may belong to
to which a part    more than one        only one
may belong         aggregate at a       composite at a
                   time                 time
   Inheritance is a mechanism in OOP to
    design two or more entities that are
    different but share many common
       Features common to all classes are defined in
        the superclass.
       The classes that inherit common features from
        the superclass are called subclasses.
         We also call the superclass an ancestor and the

          subclass a descendant.
    A Sample of Inheritance
   Here are the superclass Vehicle and its
    subclasses Car, Boat and Truck.

        Car          Boat        Truck
    Inheritance models the is-an-extension-of
    relationship between two classes.
public class Car extends Vehicle {
  /** Data fields */
  /** Constructors */
  /** Methods */

public class Boat extends Vehicle {
  /** Data fields */
  /** Constructors */
  /** Methods */

        Inheritance Hierarchy
         An example of inheritance hierarchy
          among different types of students.

                Graduate                 Undergrad

Masters        Doctoral    Law       Commuting       Resident
Example of class diagram with multiplicities,
attributes and operations
Key Concepts
   OOP                             Variable

   Class                           Constant

   Object                          Inheritance

   Message                         Superclass

   Class and instance methods      Subclass

   Instance and class data


To top