Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming With Java ICS201 University Of Hail1 Chapter 12 UML and Patterns.

Similar presentations


Presentation on theme: "Programming With Java ICS201 University Of Hail1 Chapter 12 UML and Patterns."— Presentation transcript:

1 Programming With Java ICS201 University Of Hail1 Chapter 12 UML and Patterns

2 Programming With Java ICS201 University Of Hail2 Introduction to UML oUML (Unified Modeling Language) is a graphical language used for designing and documenting OOP software. oUML is a software design tools that can be used within the context of any OOP (Object-Oriented programming) language.

3 Programming With Java ICS201 University Of Hail3 UML oPseudocode is a way of representing a program in a linear and algebraic manner.  It simplifies design by eliminating the details of programming language syntax. oGraphical representation systems for program design have also been used:  Flowcharts and structure diagrams for example. oUnified Modeling Language (UML) is yet another graphical representation formalism.  UML is designed to reflect and be used with the OOP philosophy.

4 Programming With Java ICS201 Types of UML Diagrams Use Case Diagram Class Diagram Sequence Diagram Collaboration Diagram State Diagram ….

5 Programming With Java ICS201 5 Classes A class is simply represented as a box with the name of the class inside –The diagram may also show the attributes and operations –The complete signature of an operation is: operationName(parameterName: parameterType …): returnType Rectangle height width getArea resize Rectangle height width Rectangle getArea resize Rectangle height: int width: int getArea(): int resize(int,int)

6 Programming With Java ICS201 University Of Hail6 UML Class Diagram oA class diagram is divided up into three sections: 1.The top section contains the class name. 2.The middle section contains the data specification for the class (attributes). 3.The bottom section contains the actions or methods of the class (operations). ClassName attributes operations

7 Programming With Java ICS201 Class Names ClassName attributes operations The name of the class is the only required tag in the graphical representation of a class. It always appears in the top-most compartment.

8 Programming With Java ICS201 Software Design (UML) Class Attributes (Cont’d) Person + name : String # address : Address # birthdate : Date / age : Date - ssn : Id Attributes can be: + public # protected - private / derived Attributes are usually listed in the form: attributeName : Type A derived attribute is one that can be computed from other attributes. For example, a Person’s age can be computed from his birth date. / age : Date

9 Programming With Java ICS201 Software Design (UML) Class Operations Person name : String address : Address birthdate : Date ssn : Id eat sleep work play Operations describe the class behavior and appear in the third compartment. oEach method in a UML diagram is indicated by the name of the method, followed by its parameter list, a colon (:), and its returned type.

10 Programming With Java ICS201 University Of Hail10 UML Class Diagram oA class diagram need not give a complete description of the class. oIf a given analysis does not require that all the class members be represented, then those members are not listed in the class diagram. oMissing members are indicated with an ellipsis (three dots).

11 Programming With Java ICS201 University Of Hail11 Example (UML Class Diagram) Square - Side : double - xCoordinate : double - yCoordinate : double + resize (double newSide) : void + move (double newx, double newy ) : void # erase ( ) : void … attributes Class methods Class name

12 Programming With Java ICS201 University Of Hail12 Inheritance Diagrams ( Generalization) oAn inheritance diagram shows the relationship between a base class and its derived class(es).  Normally, only as much of the class diagram is shown as is needed.  Note that each derived class may serve as the base class of its derived class(es). oEach base class is drawn above its derived class(es)  An upward pointing arrow is drawn between them to indicate the inheritance relationship.

13 Programming With Java ICS201 University Of Hail13 Inheritance Diagrams oThe arrows also help in locating method definitions. oTo look for a method definition for a class:  Examine the class definition first.  If the method is not found, the path of connecting arrows will show the order and direction in which to search.  Examine the parent class indicated by the connecting arrow.  If the method is still not found, then examine this parent's parent class indicated by the connecting arrow.  Continue until the method is found, or until the top base class is reached.

14 Programming With Java ICS201 University Of Hail14 A Class Hierarchy in UML Notation StudentEmployee StaffUndergraduate Person GraduateFaculty Arrows go from a derived class to its base class.

15 Programming With Java ICS201 University Of Hail15 Some Details of a Class Hierarchy + setName(String newName): void + getName( ): String + toString( ): String + sameName(Person otherPerson): boolean - name: String Person + set(String newName, int newStudentNumber): void + getStudentNumber( ): int + setStudentNumber(int newStudentNumber ): void + toString( ): String + equals(Object otherObject): boolean - studentNumber: int Student

16 Programming With Java ICS201 Example Consider the class named Book that contains: –A private String variable called title; –A private integer variable called nbpages; –A public double variable called price ; –Two public methods SetTitle() and SetNbpages(); –Two public methods getTitle() and getNbpages(); Class TextBook is a derived class from the class Book. It contains: –A protected integer variable called gradeLevel; –A public method toString() that returns a description of a textBook; –A public method PriceAfterDiscount() that returns the price of a book after applying a discount of 10%. Question: Establish the UML diagram for this problem.

17 Programming With Java ICS201 Book - title : String - nbpages : int + price : double + SetTitle (String t) : void + SetNbpages (int nb) : void + getTitle ( ) : String + getNbpages ( ) : int TextBook # gradeLevel : int + toString ( ) : String + PriceAfterDiscount() : double


Download ppt "Programming With Java ICS201 University Of Hail1 Chapter 12 UML and Patterns."

Similar presentations


Ads by Google