Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unified Modeling Language (UML)

Similar presentations


Presentation on theme: "Unified Modeling Language (UML)"— Presentation transcript:

1 Unified Modeling Language (UML)
AP Java Unified Modeling Language (UML)

2 Be able to model a single class using Unified Modeling Language (UML)
Learning Objectives Be able to model a single class using Unified Modeling Language (UML) Use a UML diagram to help create a class.

3 Big questions What is UML? What is a UML class diagram?
Why should I bother? Do people really use UML? What is a UML class diagram? What kind of information goes into it? How do I create it? When should I create it?

4 Design phase design: specifying the structure of how a software system will be written and function, without actually writing the complete implementation a transition from "what" the system must do, to "how" the system will do it What classes will we need to implement a system that meets our requirements? What fields and methods will each class have? How will the classes interact with each other?

5 How do we design classes?
class identification from project spec / requirements nouns are potential classes, objects, fields verbs are potential methods or responsibilities of a class UML diagrams class diagrams (today) sequence diagrams ...

6 Introduction to UML UML: pictures of an Object Oriented (OO) system
programming languages are not abstract enough for OO design UML is an open standard; lots of companies use it What is legal UML? a descriptive language: rigid formal syntax (like programming) a prescriptive language: shaped by usage and convention it's okay to omit things from UML diagrams if they aren't needed by team/supervisor/instructor

7 Uses for UML as a sketch: to communicate aspects of system
forward design: doing UML before coding backward design: doing UML after coding as documentation often done on whiteboard or paper used to get rough selective ideas as a blueprint: a complete design to be implemented sometimes done with CASE (Computer-Aided Software Engineering) tools as a programming language: with the right tools, code can be auto-generated and executed from UML only good if this is faster than coding in a "real" language

8 UML class diagrams What is a UML class diagram?
UML class diagram: a picture of the classes in an OO system, their fields and methods, and connections between the classes that interact or inherit from each other What are some things that are not represented in a UML class diagram? details of how the classes interact with each other algorithmic details; how a particular behavior is implemented

9 Diagram of one class class name in top of box
attributes (Instance Variables) should include all fields of the object operations / methods may omit trivial (get/set) methods but don't omit any methods from an interface! should not include inherited methods

10 Class attributes/Variables
attributes (fields, instance variables) visibility name : type [count] = default_value visibility: + public (all) # protected (family) - private (me) ~ package (default/Folder) / derived underline static attributes/class variables derived attribute: not stored, but can be computed from other attribute values attribute example: - balance : double = 0.00

11 Class operations / methods
visibility name (parameters) : return_type visibility: + public # protected - private ~ package (default) underline static methods parameter types listed as (name: type) omit return_type on constructors and when return type is void method example: + distance(p1: Point, p2: Point): double

12 Practice: In your notes… Create a UML Diagram for a Fraction class
Default Constructor Constructor given integer numerator/denominator Multiply by a Fraction object and return the product as a Fraction object Add to a Fraction object and return the sum as a Fraction object. toString. Return a String representation of the object.

13 Using the UML To Help with a Free Response Question
In the next section you will create a UML Diagram for the Quiz Question Then we will go over creating the class as a class. Read over the Question and Create a UML diagram for the TextFormatter class.

14 Part A private int findString(String str,int start)
Hands On: line = “aabaccb” Pseudo Code Find first occurrence of str in line (position). While there is an occurrence of str in line If it is a single occurrence (not a duplicate) Return this position Else //If it matches the letter before and/or after Find the next occurrence of str in line Return -1 (No single occurrences) Checking for Single Occurrence If it is the first letter (position = 0) check to make sure it does not match the next letter. Else If it is the last letter (position =line.length() -1) Check to make sure it does not match the previous letter. Else Check to make sure it does not match the previous or next letter TextFormatter - line : String + TestFormatter(lineToFormat:String) findString( str: String, start:int):int countStrings(str:String): int

15 Problem A More Refined Pseudo Code
Find first occurrence of str in line (position). While there is an occurrence of str in line If it is the first letter (position = 0) if it does not match the next letter. Return this position Else If it is the last letter (position =line.length() -1) If it does not match the previous letter. Else //if it is not the first or last position in line If it does not match the previous or next letter Else //If it matches the letter before and/or after Find the next occurrence of str in line Return -1 (No single occurrences)

16 Modify the following Driver Class for Testing

17 Part b: countStrings This method will be sent a single character string (str) and will count the number of times single instances of the goal string appears in the String line.

18 Part b Pseudo Code Start a position 0 and count 0
While there is str in line from position Add to the count add one to position Return the count

19 Part c: convertItalics()
If there are an even number of “_” then for each pair of “_” replace “<I>” marking the beginning of a section of “_” “</I>” marking the end of a section Returning the converted String

20 Pseudo Code If there are an odd number of “_” then
Return the original ‘line’ Make a temporary String (answer) to add the modified String Make front and back variables for copying the parts of line into answer String For each pair of “_” Replace the first “_” with “<I>” Set back to findString(“_”, front) Add string from front to back and “<I>” to answer Set front to back + 1 Replace the second with “</I>” Add string from front to back and “</I>” to answer Add the rest of the String to the answer Return answer

21 Assignment Complete the TextFormatter class and driver class to test it.


Download ppt "Unified Modeling Language (UML)"

Similar presentations


Ads by Google