Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fundamentals of Software Development 1

Similar presentations


Presentation on theme: "Fundamentals of Software Development 1"— Presentation transcript:

1 Fundamentals of Software Development 1
4/19/2019 Today’s Summary Interfaces What are they? Why are they important? How do they relate to WordGames? Why classes are important UML class diagrams Implementing your own classes Defining a method By using documented stubs Parameters and returned values Invoking a method Summarized on the next few slides Fundamentals of Software Development 1 Rose-Hulman Institute of Technology

2 Why have interfaces? A Java interface is the “face” that one class shows others An interface contains the signature but not body for each method Any class that implements an interface must provide the methods listed in the interface So an interface specifies a contract public interface ClockRadio { public Time getTime(); public void setTime(Time x); public void setTime(Time x, Station s); } Example of a Java interface Fundamentals of Software Development 1

3 UML class diagram for WordGames
All our stuff The StringTransformable interface is how our code knows how to “connect” to your code <<interface> StringTransformable transform(String) : String Capitalizer NameDropper xxx xxx Questions on this important idea? Fundamentals of Software Development 1

4 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

5 Review: UML class diagrams
Fundamentals of Software Development 1 4/19/2019 Review: UML class diagrams What they are A notation to assist object-oriented design (not just Java) Why use UML? UML as sketch 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 This is how we (and most people) use UML class diagrams – as a tool to help our thinking Fundamentals of Software Development 1 Rose-Hulman Institute of Technology

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

7 UML class diagram with details
Fundamentals of Software Development 1 4/19/2019 UML class diagram with details EyeBall Together, let’s examine JavaEyes and fill in the details for the EyeBall class in the UML class diagram What are the attributes? Their types? Any comments needed? What are the operations? Their types? eyeBallColor : Color xPosition : int yPosition : int radius : int Sets the EyeBall color to the given color EyeBall(Color eyeBallColor) draw( Graphics graphics) look(int x, int y) Moves the EyeBall to follow the mouse to the given (x, y) point There are two ways to show an object-type attribute: Draw a HAS-A arrow to it List it in the detailed box Choose the former if you want to emphasize the relationship Questions? Fundamentals of Software Development 1 Rose-Hulman Institute of Technology

8 Method invocation versus definition
Fundamentals of Software Development 1 4/19/2019 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 Rose-Hulman Institute of Technology

9 Method invocation versus definition
Fundamentals of Software Development 1 4/19/2019 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 Rose-Hulman Institute of Technology

10 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 NameDropper class in the blue box defines: A field called myName to hold the NameDropper’s name to drop A constructor called NameDropper 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 NameDropper constructor and transform method to run They each run several times, with different actual arguments substituted for the formal parameters in the NameDropper definition These statements would themselves appear in some other class Fundamentals of Software Development 1

11 private String myName;
public class NameDropper extends StringTransformer implements StringTransformable { private String myName; public NameDropper(String nameToUse) { this.myName = nameToUse; } public transform(String phrase) { return this.myName + “says ” + phrase; } } Definition of the NameDropper class NameDropper person1, person2, person3; person1 = new NameDropper(“Calvin”); person2 = new NameDropper(“Hobbes”); person3 = new NameDropper(“lobster”); person1.transform(“you look funny today, Hobbes.”); person2.transform(“you looker even funnier.”); person1.transform(“no, YOU look funnier.”); person3.transorm(“I amd just a lonely lobster.”); Invoking the NameDropper constructor and transform method Questions? Fundamentals of Software Development 1

12 Implementing by using documented stubs
Stub: a method whose body is either: empty (if the method returns nothing), or trivial, for example: return null (if the method returns an object) return 999 (if the method returns a number) return true (if the method returns a boolean) Documented stub: a stub with appropriate Javadoc Example on next slide Fundamentals of Software Development 1

13 Implementing by using documented stubs
Stub: a method whose body is either empty or trivial Documented stub: a stub with appropriate Javadoc Implementing by using documented stubs /** * A StringTransformer that transforms the phrase that it is given * by capitalizing it. * David Mutchler. */ public class Capitalizer extends StringTransformer implements StringTransformable {     /**     * Does nothing beyond constructing the Capitalizer.     */     public Capitalizer() {     }     /**     * Capitalizes each letter of the given phrase and return the result.     *     thePhrase The phrase to transform.     The capitalized version of the given phrase.     */     public String transform(String thePhrase) { return null;     } } Questions? Stub Stub, to be filled in later by: return this.myName + “says ” + phrase; Fundamentals of Software Development 1

14 What’s Ahead? Before the next session: Next week – Details to follow:
Reminder: Find the homework assignment from the Schedule page of the CSSE 120 Angel site angel.rose-hulman.edu What’s Ahead? Before the next session: Do Homework 7 (no late homework!) Including the reading and the associated online quiz Next session: More WordGames - Implementing your own classes! Next week – Details to follow: Review session Tuesday night First exam Wednesday night Our usual 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


Download ppt "Fundamentals of Software Development 1"

Similar presentations


Ads by Google