DOC PREVIEW
UNF COP 2551 - Lecture Notes

This preview shows page 1-2-16-17-18-33-34 out of 34 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 34 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Chapter 6OutlineEnumerated TypesSlide 4Slide 5Slide 6Slide 7Slide 8Slide 9Method DesignSlide 11Method DecompositionSlide 13Slide 14Slide 15Class Diagram for Pig Latin Objects as ParametersPassing Objects to MethodsBottom Line – Know This.Slide 20Slide 21Slide 22 Method OverloadingMethod OverloadingSlide 25Overloading MethodsSlide 27TestingSlide 29Reviews Test CasesDefect and Regression Testing Black-Box Testing White-Box TestingChapter 6Object-Oriented DesignPart 3© 2004 Pearson Addison-Wesley. All rights reserved 6-2OutlineEnumerated Types RevisitedMethod DesignTesting© 2004 Pearson Addison-Wesley. All rights reserved 6-3Enumerated Types•In Chapter 3 we introduced enumerated types, which define a new data type and list all possible values of that typeenum Season {winter, spring, summer, fall}•Once established, the new type can be used to declare variablesSeason time; // Note: no quotes around time.•The only values this variable can be assigned are the ones established in the enum definition© 2004 Pearson Addison-Wesley. All rights reserved 6-4Enumerated Types•An enumerated type definition is a special kind of class•The values of the enumerated type are or objects of that type•For example, fall is an object of type Season•Fall is ‘associated’ with a list of values.•That's why the following assignment is validtime = Season.fall;© 2004 Pearson Addison-Wesley. All rights reserved 6-5Enumerated Types•An enumerated type definition can be more interesting than a simple list of values•Because they are like classes, we can add additional instance data and methods•We can define an enum constructor as well•Each value listed for the enumerated type calls the constructor•See Season.java (page 318)•See SeasonTester.java (page 319)•DO go through these routines.© 2004 Pearson Addison-Wesley. All rights reserved 6-6// Season.java Author: Lewis/Loftus// Enumerates the values for Season.//********************************************************************public enum Season //Note: this is NOT a class! You do NOT see ‘class’ here…{ winter ("December through February"), // Note the syntax: the comma?? spring ("March through May"), summer ("June through August"), fall ("September through November"); // and ultimately the semicolon! // Note that this is a new ‘data type’ And we list all possible values of this type. // The only values of this type are winter, spring, summer, and fall. private String span; //----------------------------------------------------------------- // Constructor: Sets up each value with an associated string. //----------------------------------------------------------------- Season (String months) // Note the Constructor; kind of ‘like’ a Constructor. { span = months; } //----------------------------------------------------------------- // Returns the span message for this value. //----------------------------------------------------------------- public String getSpan() { return span; }} // end enum Season© 2004 Pearson Addison-Wesley. All rights reserved 6-7//********************************************************************// SeasonTester.java Author: Lewis/Loftus//// Demonstrates the use of a full enumerated type.//********************************************************************public class SeasonTester{ //----------------------------------------------------------------- // Iterates through the values of the Season enumerated type. //----------------------------------------------------------------- public static void main (String[] args) { for (Season time : Season.values()) // note: ‘time is a ‘variable’ of enum Season.This invokes enum types via Season.values(). Very neat! When we declare ‘time’, System.out.println (time + "\t" + time.getSpan()); }}© 2004 Pearson Addison-Wesley. All rights reserved 6-8Enumerated Types•Every enumerated type contains a static method called values that returns a list of all possible values for that type The list returned from values is an iterator, so a for loop can be used to process them easily (infer that there is a next() and a hasNext() method.•An enumerated type cannot be instantiated outside of its own definition•A carefully designed enumerated type provides a versatile and type-safe mechanism for managing data© 2004 Pearson Addison-Wesley. All rights reserved 6-9OutlineSoftware Development ActivitiesIdentifying Classes and ObjectsStatic Variables and MethodsClass RelationshipsInterfacesEnumerated Types RevisitedMethod DesignTesting© 2004 Pearson Addison-Wesley. All rights reserved 6-10Method Design•As we've discussed, high-level design issues include: identifying primary classes and objects assigning primary responsibilities•After establishing high-level design issues, its important to address low-level issues such as the design of key methods•For some methods, careful planning is needed to make sure they contribute to an efficient and elegant system design© 2004 Pearson Addison-Wesley. All rights reserved 6-11Method Design•An algorithm is a step-by-step process for solving a problem•Examples: a recipe, travel directions Every method implements an algorithm that determines how the method accomplishes its goals•An algorithm may be expressed in pseudocode, a mixture of code statements and English that communicate the steps to take© 2004 Pearson Addison-Wesley. All rights reserved 6-12Method Decomposition•A method should be relatively small, so that it can be understood as a single entity•A potentially large method should be decomposed into several smaller methods as needed for clarity•A public service method of an object may call one or more private support methods to help it accomplish its goal•Support methods might call other support methods if appropriate© 2004 Pearson Addison-Wesley. All rights reserved 6-13Method Decomposition•Let's look at an example that requires method decomposition – translating English into Pig Latin•Pig Latin is a language in which each word is modified by moving the initial sound of the word to the end and adding "ay"•Words that begin with vowels have the "yay" sound added on the endbook ookbay table abletayitem itemyay chair airchay© 2004 Pearson Addison-Wesley. All rights reserved 6-14Method Decomposition•The primary objective (translating a sentence) is too


View Full Document

UNF COP 2551 - Lecture Notes

Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?