Todays Summary UML class diagrams Why classes are

  • Slides: 10
Download presentation
Today’s Summary • UML class diagrams – – – Why classes are important UML

Today’s Summary • UML class diagrams – – – Why classes are important UML class diagrams – relationships UML class diagrams – details for each class • Methods – Invoking a method – Defining a method Fundamentals of Software Development 1 Summarized on the next few slides Summarized on the slides after the above summary 1

Why classes are important • What does an object’s type tell you? – Answer:

Why classes are important • What does an object’s type tell you? – Answer: How the object operates! • What attributes the object has • What operations the object can do • Fact: The type of an object is simply the name of the class to which the object belongs • What can you conclude from the above statements? • Answer: The class (i. e. type) of an object tells you how the object operates! Questions? Fundamentals of Software Development 1 2

Review: UML class diagrams • What they are – A notation to assist object-oriented

Review: UML class diagrams • What they are – A notation to assist object-oriented design (not just Java) • Why use UML? – UML as sketch This is how we (and most people) use UML class diagrams – as a tool to help our thinking • To figure out a design • To communicate ideas and alternatives – UML as blueprint • To convey the design to the coder – UML as programming language • To generate code automatically from the design Fundamentals of Software Development 1 3

Review: UML class diagrams – relationships-only 1 * 1. . * 0. . 1

Review: UML class diagrams – relationships-only 1 * 1. . * 0. . 1 is-a (by extending a class) is-a (by implementing an interface) has-a Order 1 line. Item 1 * means one means 0 or more means 1 or more means 0 or 1 Customer * Order Line * Corporate Customer 1 Product * 0. . 1 sales. Rep Employee Fundamentals of Software Development 1 Personal Customer Questions? 4

UML class diagram with details • Together, let’s examine Java. Eyes and fill in

UML class diagram with details • Together, let’s examine Java. Eyes and fill in the details for the Eye. Ball class in the UML class diagram • What are the attributes? Their types? – Any comments needed? Eye. Ball eye. Ball. Color : Color x. Position : int y. Position : int Sets the Eye. Ball color to the given color radius : int Eye. Ball(Color eye. Ball. Color) • What are the operations? draw( Graphics graphics) Their types? look(int x, int y) – Any comments needed? There are two ways to show an object-type attribute: • Draw a HAS-A arrow to it Fundamentals of Software • List it in the detailed box Development 1 Questions? Choose the former if you want to emphasize the relationship Moves the Eye. Ball to follow the mouse to the given (x, y) point 5

Method invocation versus definition • “There is a difference between knowing the path and

Method invocation versus definition • “There is a difference between knowing the path and walking the path. ” ~ Morpheus • “There is a difference between defining a method and invoking a method. ” ~ CSSE Prof. Fundamentals of Software Development 1 6

Method invocation versus definition • To define (write) a method means to write its

Method invocation versus definition • To define (write) a method means to write its code – The code is a recipe to follow when the method runs – Methods often have parameters – information that comes into the method when it is run • To invoke (call, run) a method means to cause the method’s code to run – Sending it actual values to substitute for the formal parameters of the method • Example (on next slides) Fundamentals of Software Development 1 7

Method invocation versus definition • To define (write) a method means to write its

Method invocation versus definition • To define (write) a method means to write its code • To invoke (call, run) a method means to cause the method’s code to run • Example (on next slide): – The Name. Dropper class in the blue box defines: • • A field called my. Name to hold the Name. Dropper’s name to drop A constructor called Name. Dropper that takes the name to store in the field • A method called transform that takes a phrase to tranform – The statements in the yellow box cause the Name. Dropper constructor and transform method to run • They each run several times, with different actual arguments substituted for the formal parameters in the Name. Dropper definition • Software These statements would themselves appear in some other class Fundamentals of Development 1 8

public class Name. Dropper extends String. Transformer implements String. Transformable { private String my.

public class Name. Dropper extends String. Transformer implements String. Transformable { private String my. Name; public Name. Dropper(String name. To. Use) { this. my. Name = name. To. Use; } Definition of the Name. Dropper class public transform(String phrase) { return this. my. Name + “says ” + phrase; } } Name. Dropper person 1, person 2, person 3; Invoking the person 1 = new Name. Dropper(“Calvin”); Name. Dropper constructor and person 2 = new Name. Dropper(“Hobbes”); transform method person 3 = new Name. Dropper(“lobster”); person 1. transform(“you look funny today, Hobbes. ”); person 2. transform(“you looker even funnier. ”); person 1. transform(“no, YOU look funnier. ”); Fundamentals of Software Development 1 9 person 3. transorm(“I amd just a lonely lobster. ”);

What’s Ahead? • Before the next session: Reminder: Find the homework assignment from the

What’s Ahead? • Before the next session: Reminder: Find the homework assignment from the Schedule page of the CSSE 120 Angel site angel. rose-hulman. edu – Do Homework 6 (no late homework!) • Including the reading and the associated online quiz – Next session: • Word. Games - Implementing your own classes! Suggestion: Routinely do your homework in F-217 (CSSE lab). A student assistant is there every Sunday through Thursday evening, 7 pm to 9 pm, so you can get immediate answers to any questions you might have. Fundamentals of Software Development 1 10