Chapter02-Object Oriented Design Using UML2.0

Document Sample
Chapter02-Object Oriented Design Using UML2.0 Powered By Docstoc
					BCS 2143

 Object Oriented Design Using
             UML
Objectives
   Objects Interactions
   Finding Classes
   Relationship Between Classes
   Attribute and Operation
   Class Diagram
Outline
   Name the basic components of object-oriented design using
    UML
   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
                                                                  objects
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

  ATM
Maintainer
              Maintain ATM Machine
Class Diagram
   Diagram that consists of several classes or
    objects.
   Object :
       represent specific entity in term of physical and
        conceptual
       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
                                                          Windows


                                                           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

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




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




Example:

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

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




Example:

                                    This tells an object
                                    PersonA is an instance
          PersonA : BankAccount
                                    of the BankAccount
                                    class.
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.




                           deposit(250.00)
                                               PersonA : BankAccount




                      myWindow.setVisible(true);
Examples              personA.deposit( 250.0 );
                      student.setName(“john”);
                      car1.startEngine( );
  Sending a Message and
  Getting an Answer
Ask for the current
balance of this
particular account.



                      getCurrentBalance()
                                                     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
returned.




                                             MobileRobot
                         getMaximumSpeed()


                             maximum speed
Class and Instance Data
Values
   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
    information.
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
                                              different.
          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
instance-of
relationship.


    Ali : BankAccount    Ani : BankAccount   Siti : BankAccount


       current balance     current balance     current balance
           908.55             1304.98              354.00
Object Icon with Class Data
Value
     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.
            908.55
Class
   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
     Class/Attribute/Method/Object
                      Student                  Class

                       name
                        age                  Attribute
                      course                 (variable)
                        fees

                  registerSubject
                                               Method
                 withdrawSubject
                                             (operation)
                   borrowBook

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

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

     public void registerSubject (){
               // code for register subject
     }
     …
}
       Java Code :
       Object Declaration /
       Manipulation
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
                                              initialize
           Std1.name = " Amad“ ; // assigning value to object
           Std1.age = 24 ; // assigning value to object
           System.out.println(" student name : " + Std1.name) ;
           System.out.println(" student age registration : " +
                              Std1.age) ;
       }

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


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.
Aggregation
   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
Composition
   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
    composite
    Example of Composition

                  Chair




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
   Inheritance is a mechanism in OOP to
    design two or more entities that are
    different but share many common
    features.
       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.
                    Vehicle




        Car          Boat        Truck
    Inheritance
    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.
                           Student




                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

    values
Q&A

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:10
posted:8/19/2012
language:English
pages:42