AP Computer Science Chapter 2 Notes

75
CHAPTER 2 CHAPTER 2 An Introduction to An Introduction to Objects and Classes Objects and Classes

description

AP computer science chapter 1 notes

Transcript of AP Computer Science Chapter 2 Notes

CHAPTER 2CHAPTER 2

An Introduction to Objects An Introduction to Objects and Classesand Classes

ClassesClasses

Class:Class: Set of objects with the Set of objects with the same behavior, describes same behavior, describes characteristics and behavior of characteristics and behavior of an object.an object.

Each class can have instances of Each class can have instances of multiple objectsmultiple objects

Written in a file all its ownWritten in a file all its own

ObjectsObjects

Object:Object: real world entity that real world entity that you can manipulate in your you can manipulate in your programs (by invoking methods) programs (by invoking methods)

Each object belongs to a classEach object belongs to a class

Object vs ClassObject vs Class

►Object is an instance of a classObject is an instance of a class►CookieCookie

►Class is a blueprint for an Class is a blueprint for an objectobject

►Cookie CutterCookie Cutter

Create an instance of an Create an instance of an objectobject

► Instantiation of an object creates an Instantiation of an object creates an instance of an object and the instance of an object and the parameters passed into the parameters passed into the constructor will initialize the private constructor will initialize the private instance fields….keyword instance fields….keyword newnew

►Car c = Car c = newnew Car(“blue”, 1999); Car(“blue”, 1999);

An Object…An Object…

► An object has An object has data fieldsdata fields, which hold values , which hold values that can change while the program is that can change while the program is running. A piece of data maybe another running. A piece of data maybe another object.object.

► An object has a set of An object has a set of methodsmethods that can that can process messages of certain types. A process messages of certain types. A method can change the object’s state, send method can change the object’s state, send messages to other objects, and create new messages to other objects, and create new objects.objects.

Class ObjectClass Object►A blueprint for A blueprint for

objects of a objects of a particular typeparticular type

►Defines the Defines the structure structure (number, types) (number, types) of the attributesof the attributes

►Defines available Defines available behaviors of its behaviors of its objectsobjects

Attributes

Behaviors

Class: Car Object: my Class: Car Object: my carcar

Attributes: String model Color color int numPassengers double amountOfGas

Behaviors: Add/remove a passenger Get the tank filled Report when out of gas

Attributes: model = "Mustang" color = Color.YELLOW numPassengers = 0 amountOfGas = 16.5

Behaviors:

Class vs. ObjectClass vs. Object

Written by a Written by a programmer programmer

Example: class Robot which Example: class Robot which keeps track of its initial keeps track of its initial location, current location location, current location and direction facing … with and direction facing … with behaviors such as turn and behaviors such as turn and step forward.step forward.

Created when the Created when the program is program is running (by the running (by the main method or a main method or a constructor or constructor or another method) another method)

Example: R2D2 or WallEExample: R2D2 or WallE

OOP —OOP —OObject-bject-OOriented riented PProgrammingrogramming

►An OO program models the application An OO program models the application as a world of interacting objects.as a world of interacting objects.

►An object can create other objects.An object can create other objects.

►An object can call another object’s An object can call another object’s (and its own) methods (that is, “send (and its own) methods (that is, “send messages”).messages”).

OOP BenefitsOOP Benefits

►Facilitates team developmentFacilitates team development

►Easier to reuse software components Easier to reuse software components and write reusable softwareand write reusable software

►Easier GUI (Easier GUI (GGraphical raphical UUser ser IInterface) nterface) and multimedia programmingand multimedia programming

Objects in the Objects in the Dance StudioDance Studio ProgramProgram

Dancer

Foot

Dance floorControl panel

Go / Stop button

Dance selection pulldown list

Positioning button

Dance Studio window

Band

Dance group

Waltz, etc.

Dance step

Classes and Source FilesClasses and Source Files

►Each class is stored in a separate fileEach class is stored in a separate file►The name of the file must be the same The name of the file must be the same

as the name of the class, with the as the name of the class, with the extension .javaextension .java

public class Car{ ...}

Car.java By convention, the name of a class (and its source file) always starts with a capital letter.

(In Java, all names are case-sensitive.)

3 parts to every class3 parts to every class

►Fields/Instance Fields/Instance Fields/Instance Fields/Instance Variables /private data Variables /private data members/Attributesmembers/Attributes

►Methods/BehaviorsMethods/Behaviors

►ConstuctorsConstuctors

public class SomeClasspublic class SomeClass

►FieldsFields

►ConstructorsConstructors

►MethodsMethods}}

Attributes / variables that define the object’s state; can hold numbers, characters, strings, other objects

Procedures for constructing a new object of this class and initializing its fields

Actions that an object of this class can take (behaviors)

{

Class header

SomeClass.java

import ... import statements

Object Diagrams and Object Diagrams and Access to all the partsAccess to all the parts

private fields

____________

____________

____________

public method

___________

public method

___________

public constructor

___________

Part 1 - FieldsPart 1 - Fields

►Constitute “private memory” of an Constitute “private memory” of an objectobject

►Each field has a Each field has a data typedata type (int, double, (int, double, String, boolean, char, or another type String, boolean, char, or another type of object)of object)

►Each field has a name given by the Each field has a name given by the programmerprogrammer

FieldsFields

► Should always be of private access typeShould always be of private access type

► Can be used by any method within the same Can be used by any method within the same class.class.

► From within the class, From within the class, just refer to them by just refer to them by their names. their names.

► From outside the class in another file such as From outside the class in another file such as main, the only way we can access them is via main, the only way we can access them is via methods of the class.methods of the class.

Syntax 2.6 : Instance Field Syntax 2.6 : Instance Field DeclarationDeclaration

►accessSpecifieraccessSpecifier class class ClassNameClassName{ { ... ... accessSpecifier fieldType fieldNameaccessSpecifier fieldType fieldName;;

... ... }}

► accessSpecifieraccessSpecifier could be private, public, could be private, public, protectedprotected

► fieldTypefieldType could be int, double, String, could be int, double, String, boolean, charboolean, char

private datatype name;

Fields (cont’d)Fields (cont’d)

Usually private

int, double, etc., or an object: String, Image, Foot

You name it!

private double cost;private String name;private int age;

An objects STATEAn objects STATE

►Each object of a class has it’s own set of Each object of a class has it’s own set of instance fields.instance fields.

►An object stores it’s state in one or more An object stores it’s state in one or more variables called INSTANCE FIELDS/DATA.variables called INSTANCE FIELDS/DATA.

►What is in these private variables What is in these private variables indicate the STATE of an object.indicate the STATE of an object.

Part 2 - ConstructorsPart 2 - Constructors

►A constructor is special A constructor is special procedure for constructing an procedure for constructing an object. object.

►PURPOSE: Initialize the PURPOSE: Initialize the object’s fieldsobject’s fields

ConstructorsConstructors

►Always have the same name as the Always have the same name as the classclass

►Always publicAlways public

►No return typeNo return type

►May or may not take parametersMay or may not take parameters

ConstructorsConstructors public class Car()public class Car(){{ public public CarCar(int m)(int m) { { miles = m; miles = m; } } . . . . . .}}

Syntax 2.7 : Constructor Syntax 2.7 : Constructor ImplementationImplementation

To define the behavior of a constructor, To define the behavior of a constructor, which is used to initialize the instance which is used to initialize the instance fields of newly created objectsfields of newly created objects

Using the “new” keywordUsing the “new” keyword

Invoked in Invoked in newnew expression expressionnew Car(15000) new Car(15000)

For now we will construct an For now we will construct an object in the main file.object in the main file.

More on constructorsMore on constructors►Not a methodNot a method

►overloading common practice, same overloading common practice, same signature, different parameter listssignature, different parameter lists(method signature = name of method and parameter list)(method signature = name of method and parameter list)

►A class may have several constructors A class may have several constructors that differ in the number and/or types that differ in the number and/or types of their parametersof their parameters

Overloaded ConstructorsOverloaded ConstructorsThese are all differentThese are all different

public Car ( ) public Car ( ) no parameters called no parameters called the the default constructor – default constructor –

initializes all private initializes all private data data to 0 or null.to 0 or null.

public Car (int miles)public Car (int miles)

public Car (String name, int miles)public Car (String name, int miles)

public Car (int miles, String name)public Car (int miles, String name)

PUBLICPUBLIC INTERFACE OF A INTERFACE OF A CLASSCLASS

►The constructors The constructors and methods of a and methods of a class which can be class which can be seen by all.seen by all.

Public Access SpecifierPublic Access Specifier►Constructors and methods can call Constructors and methods can call

other public and private methods other public and private methods of the same class.of the same class.

►Constructors and methods can call Constructors and methods can call only only publicpublic methods of another methods of another class.class.Class X

private field

private method

Class Y

public method public method

3. Methods3. Methods

►Example: one of the behaviors of an Example: one of the behaviors of an object may be to compute something. object may be to compute something. All the objects of the class will use the All the objects of the class will use the same formula for the computation, but same formula for the computation, but the result may depend on the specific the result may depend on the specific values of object’s attributes at the values of object’s attributes at the time of the computation.time of the computation.

Method DefinitionMethod DefinitionWritten in the classWritten in the class

access specifieraccess specifier (We will always use (We will always use public)public)

return typereturn type

(int,double,char,String,boolean,void, or another (int,double,char,String,boolean,void, or another objects type – MUCH LATERobjects type – MUCH LATER) )

method namemethod name (meaningful and lowercase (meaningful and lowercase))

list of parameterslist of parameters (need types and names (need types and names

separated by commasseparated by commas) )

method body inmethod body in { } { }

Sample methodSample methodpublicpublic doubledouble addIt addIt (int number)(int number)

{{

total = total + number;total = total + number;

return total;return total;

}}

Name each colored partName each colored part

We can also have overloaded methods…We can also have overloaded methods…

public double addIt(int x, int y)public double addIt(int x, int y)

Methods (cont’d)Methods (cont’d)

►A method can return a value to the A method can return a value to the caller – again for now this is just the caller – again for now this is just the main file.main file.

►The keyword The keyword voidvoid in the method’s in the method’s header indicates that the method does header indicates that the method does not return any valuenot return any value

public void moveSideways(int distance) { ... }

Method Body is always in curly braces

2 Types of Methods2 Types of Methods

►Accessor – will access a private Accessor – will access a private variable and typically RETURN it, variable and typically RETURN it, make sure the return type make sure the return type matches the data type of the fieldmatches the data type of the field

►Modifier/Mutator – will change Modifier/Mutator – will change what is in a private field and what is in a private field and typically RETURN void.typically RETURN void.

METHOD PARAMETERSMETHOD PARAMETERS

►These are the values you pass into a These are the values you pass into a method.method.

►They will be used inside the method in They will be used inside the method in some way.some way.

►They are only a COPY of the variable They are only a COPY of the variable from where you passed it in from.from where you passed it in from.

►They can have different names from They can have different names from where you passed them in from.where you passed them in from.

Syntax 2.5: The return Syntax 2.5: The return StatementStatement

return return expressionexpression; or return;; or return;Example:Example:

return message;return message;Purpose:Purpose:

To specify the value that a method To specify the value that a method returns, and exit the method returns, and exit the method immediately. immediately.

►The return line ends the method action The return line ends the method action and returns program control to where it and returns program control to where it was called from.was called from.

METHOD IMPLEMENTATIONMETHOD IMPLEMENTATION

► A “CALL” to a methodA “CALL” to a method► For instance System.out.printl(“…”);For instance System.out.printl(“…”);

is a call to the method println in the is a call to the method println in the system class.system class.

Use a dotUse a dot

For now we will call a method from our main For now we will call a method from our main file.file.

ObjectsObjects

►Contain…Contain…

1. 1. properties/variables/fieldsproperties/variables/fields

2. methods/behaviors2. methods/behaviors3. constructors3. constructors

Object ConstructionObject ConstructionIn main for nowIn main for now

To create an new object:To create an new object:new className(parameters without types)new className(parameters without types)

This calls the constuctor which This calls the constuctor which matches the same number and matches the same number and type of parameters and initializes type of parameters and initializes the private data fields to the the private data fields to the parameter values passed in.parameter values passed in.

Object ConstructionObject Construction

ExamplesExamplesnew Rectangle(5, 10, 20, 30)new Rectangle(5, 10, 20, 30)

this would match the constructor: this would match the constructor:

public Rectangle(int x,int y,int w,int h)public Rectangle(int x,int y,int w,int h)

new Car("BMW 540ti", 2004)new Car("BMW 540ti", 2004)

this would match the constructor: this would match the constructor:

public Car(String name, int year)public Car(String name, int year)

A Rectangle ObjectA Rectangle Objectan OBJECT DIAGRAMan OBJECT DIAGRAM

Object ReferenceObject Reference

►We need to be able to reference a We need to be able to reference a particular object to so we can use it particular object to so we can use it and its data and its methods…to do and its data and its methods…to do this we must name it.this we must name it.

►Called creating an object reference.Called creating an object reference.►Each object will most likely have a Each object will most likely have a

different name or reference to it.different name or reference to it.

Creating an Object Variables or Creating an Object Variables or Object ReferenceObject Reference

►A container that stores the location of A container that stores the location of an objectan object

►MUST be initialized before you can use itMUST be initialized before you can use it

ClassName referenceName = ClassName referenceName = The right side of the equals sign now has an object The right side of the equals sign now has an object

construction call…see previous slides.construction call…see previous slides.

Object Variables/ReferenceObject Variables/Reference

Declare and optionally initializeDeclare and optionally initialize::Rectangle crispyCrunchy;Rectangle crispyCrunchy;

This only declares an object This only declares an object reference, it does NOT create the reference, it does NOT create the object itself until you use = object itself until you use = new… new…

Right now it refers to no object Right now it refers to no object …BETTER KNOWN AS …BETTER KNOWN AS NULLNULL

To use an object variableTo use an object variable

►Use the reference name along with a Use the reference name along with a dot and a method call from that class.dot and a method call from that class.

►Example: r is a reference to a Example: r is a reference to a Rectangle as in previous slide.Rectangle as in previous slide.

r.GetArea( );r.GetArea( );

2 object references referring to 2 object references referring to the same objectthe same object

►Common “gotcha” on AP multiple Common “gotcha” on AP multiple choice questions (and on my tests)choice questions (and on my tests)

►Rectangle r = new Rectangle r = new Rectangle(5,10,20,30);Rectangle(5,10,20,30);

►Rectangle cerealBox = r;Rectangle cerealBox = r;►See what happens here on the next slide.See what happens here on the next slide.►They both refer to the EXACT same object, not They both refer to the EXACT same object, not

a copy they are the SAME OBJECT.a copy they are the SAME OBJECT.

Two Object Variables Two Object Variables Referring to the Same ObjectReferring to the Same Object

Programs can use objects in Programs can use objects in the following waysthe following ways

►To construct an object with the To construct an object with the newnew keywordkeyword

►to store object references in an object to store object references in an object variablevariable

►to call methods on an object variableto call methods on an object variable

Testing a Class/Driver Testing a Class/Driver classclass Test class:Test class: a class with a main method that a class with a main method that

contains statements to test another class. contains statements to test another class.

Typically carries out the following steps:Typically carries out the following steps: ►Construct one or more objects of the Construct one or more objects of the class that is being tested. class that is being tested.

►Invoke one or more methods. Invoke one or more methods. ►Print out one or more resultsPrint out one or more results

VARIABLESVARIABLES

►Lots of different kind of variables.Lots of different kind of variables.►So far we have discussed:So far we have discussed:

private private instance variablesinstance variables in a in a classclass

object referenceobject reference variables variables

parametersparameters being passes into being passes into methods or methods or constructors.constructors.

►There are more…There are more…

Local Variables - Local Variables - used used anywhereanywhere

►created in a block of code – created in a block of code – enclosed within a set of curly enclosed within a set of curly braces.braces.

►Could be in a methodCould be in a method►Could be in the main class fileCould be in the main class file►They exist only within that block They exist only within that block

of code – die upon closing braceof code – die upon closing brace

General Definition of a General Definition of a VariableVariable

►An item of information in memory whose An item of information in memory whose location is identified by a name.location is identified by a name.

►Holds data of some sortHolds data of some sort

►Every variable has a type which defines Every variable has a type which defines what kind of information it will hold, what kind of information it will hold, defines how much memory to set aside.defines how much memory to set aside.

General Definition of a General Definition of a VariableVariable

► Instance fields -Do not need to be Instance fields -Do not need to be initialized, numbers default to zero, initialized, numbers default to zero, strings default to null.strings default to null.

►Local variables NEED to be initialized Local variables NEED to be initialized to something.to something.

Declaration vs DefinitionDeclaration vs Definition

int age ;int age ;

int age = 22;int age = 22;

age

age

22

Syntax 2.2: Variable Syntax 2.2: Variable DefinitionDefinition

TypeName variableNameTypeName variableName;;

TypeName variableNameTypeName variableName = = expressionexpression;;

Example:Example:

Rectangle cerealBox; Rectangle cerealBox; String name ="Dave"; String name ="Dave";

int x = 10;int x = 10; Purpose:Purpose:

To define a new variable of a particular typeTo define a new variable of a particular type

and optionally supply an initial valueand optionally supply an initial value

Naming Conventions for Naming Conventions for VariablesVariables

►Letters, digits, and underscoresLetters, digits, and underscores►No symbolsNo symbols►No reserved wordsNo reserved words►Can’t start with a digitCan’t start with a digit►case sensitive (upper/lower)case sensitive (upper/lower)

►Class Name Variables - must be Class Name Variables - must be CapitalizedCapitalized

class – first letter capitalizedclass – first letter capitalized

constant – set only once never changed – all capitalizedconstant – set only once never changed – all capitalizedprivate instance field – mySomething or specific nameprivate instance field – mySomething or specific namevariable – nounvariable – nountemporary variable - lettertemporary variable - letter

accessor method – verb “getter”accessor method – verb “getter”modifier method – verb “setter”modifier method – verb “setter”method – verbmethod – verb

Variable Catagories

Reserved WordsReserved Words► In Java a number of words are reserved for a In Java a number of words are reserved for a

special purpose.special purpose.

► Reserved words use only lowercase letters.Reserved words use only lowercase letters.

► Reserved words include:Reserved words include: primitive data types: primitive data types: intint, , doubledouble, , charchar, , booleanboolean, etc., etc. storage modifiers: storage modifiers: publicpublic, , privateprivate, , staticstatic, , finalfinal, etc., etc. control statements: control statements: ifif, , elseelse, , switchswitch, , whilewhile, , forfor, etc., etc. built-in constants: built-in constants: truetrue, , falsefalse, , nullnull

► There are about 50 reserved words total. There are about 50 reserved words total.

Programmer-Defined NamesProgrammer-Defined Names

► In addition to reserved words, Java In addition to reserved words, Java uses standard names for library uses standard names for library packages and classes:packages and classes:StringString, , GraphicsGraphics, , javax.swingjavax.swing, , JAppletJApplet,,JButtonJButton, , ActionListenerActionListener, , java.awtjava.awt

► The programmer gives names to his The programmer gives names to his or her classes, methods, fields, and or her classes, methods, fields, and variables.variables.

► Note Do NOT make a class called Note Do NOT make a class called System – it already exists you System – it already exists you overwrite it and loss all functionality.overwrite it and loss all functionality.

Names (cont’d)Names (cont’d)

► Programmers follow strict style conventions.Programmers follow strict style conventions.

► Style: Names of classes begin with an Style: Names of classes begin with an uppercaseuppercase letter, subsequent words are letter, subsequent words are capitalized:capitalized:public class public class FallingCubeFallingCube

► Style: Names of methods, fields, and Style: Names of methods, fields, and variables begin with a lowercase letter, variables begin with a lowercase letter, subsequent words are capitalized.subsequent words are capitalized.

private final int private final int delaydelay = 30; = 30;public void public void dropCubedropCube()()

Names (cont’d)Names (cont’d)

► Method names often sound like Method names often sound like verbsverbs::setBackgroundsetBackground, , getTextgetText, , dropCubedropCube, , startstart

► Field names often sound like Field names often sound like nounsnouns::cubecube, , delaydelay, , buttonbutton, , whiteboardwhiteboard

► Constants sometimes use all caps:Constants sometimes use all caps:PIPI, , CUBESIZECUBESIZE

► It is OK to use standard short names It is OK to use standard short names for temporary “throwaway” variables:for temporary “throwaway” variables:ii, , kk, , xx, , yy, , strstr

PackagePackage

►Package: a set of libraries Package: a set of libraries with many RELATED classes of with many RELATED classes of prewritten codeprewritten code

►To import a class from a package for To import a class from a package for use in a programuse in a program

Syntax 2.3 : Importing a Syntax 2.3 : Importing a Class from a PackageClass from a Package

►importimportpackageNamepackageName..ClassNameClassName ; ;

Example:Example:► import java.awt.Rectangle;import java.awt.Rectangle;

►We don’t need to import anything We don’t need to import anything with the System class in it, with the System class in it, done automatically. done automatically.

ENCAPSULATIONENCAPSULATION

► Keeping things hidden as much as possible Keeping things hidden as much as possible to keep things bug freeto keep things bug free

► Benefit: can’t accidentally put an object into Benefit: can’t accidentally put an object into an incorrect state.an incorrect state.

► Wrapping up variables and methods in such Wrapping up variables and methods in such a way so that only those things relevant to a way so that only those things relevant to the outside world are visible.the outside world are visible.

► Hiding object data and providing Hiding object data and providing methods which access them (private methods which access them (private data and public methods.)data and public methods.)

Encapsulation and Encapsulation and Information HidingInformation Hiding

►A class interacts with other classes only A class interacts with other classes only through constructors and public methodsthrough constructors and public methods

►Other classes do not need to know the Other classes do not need to know the mechanics (implementation details) of a mechanics (implementation details) of a class to use it effectivelyclass to use it effectively

►Encapsulation facilitates team work and Encapsulation facilitates team work and program maintenance (making changes to program maintenance (making changes to the code)the code)

ABSTRACTIONABSTRACTION

►Strip away to find Strip away to find the essential the essential features of an features of an object.object.

Designing the Public Designing the Public InterfaceInterface

Behavior of bank account:Behavior of bank account: deposit money deposit money withdraw money withdraw money get balance get balance

Methods of Methods of BankAccount class:BankAccount class: deposit deposit withdraw withdraw getBalancegetBalance

JavadocJavadoc

►Automatically generates a set of HTML Automatically generates a set of HTML pages that describe the classpages that describe the class

►utility which formats your comments utility which formats your comments into a new set of documents that you into a new set of documents that you can view in a web browsercan view in a web browser

►automatically creates hyperlinks to automatically creates hyperlinks to other classes and methodsother classes and methods

Javadoc Method SummaryJavadoc Method Summary

Javadoc Method DetailJavadoc Method Detail

3 reasons to comment3 reasons to comment

► First sentence used in summary table of all First sentence used in summary table of all methods, javadoc with a description of each.methods, javadoc with a description of each.

► Spend more time deciding whether or not to Spend more time deciding whether or not to do it than it does just to do it.do it than it does just to do it.

► Write method comment first to see if you Write method comment first to see if you understand what you need to program.understand what you need to program.

► Styles Styles /*for multiple lines*/ /*for multiple lines*/

//..once for each line//..once for each line

JavaDocJavaDoc

CommentsComments

► Comments are notes in plain English Comments are notes in plain English inserted in the source code.inserted in the source code.

► Comments are used to:Comments are used to: document the program’s purpose, author, document the program’s purpose, author,

revision history, copyright notices, etc.revision history, copyright notices, etc. describe fields, constructors, and methodsdescribe fields, constructors, and methods explain obscure or unusual places in the codeexplain obscure or unusual places in the code temporarily “comment out” fragments of codetemporarily “comment out” fragments of code

Formats for CommentsFormats for Comments

► A “block” comment is placed between A “block” comment is placed between /*/* and and */*/ marks: marks:/*/* Exercise 5-2 for Java Methods Exercise 5-2 for Java Methods Author: Miss BraceAuthor: Miss Brace Date: 3/5/2010Date: 3/5/2010 Rev. 1.0 Rev. 1.0 */*/

► A single-line comment goes from A single-line comment goes from //// to to the end of the line:the end of the line:wt wt **= 2.2046; = 2.2046; //// Convert to kilograms Convert to kilograms

Explicit and Implicit Explicit and Implicit ParametersParameters

public void withdraw(double amount)public void withdraw(double amount){ { double newBalance = double newBalance = balancebalance - amount; - amount; balancebalance = newBalance; = newBalance;}}

balance is the balance of the object to the left of balance is the balance of the object to the left of the dot:the dot:

momsSavingsmomsSavings.withdraw(500).withdraw(500)means means double newBalance = double newBalance = momsSavings.balancemomsSavings.balance - -

amount;amount; momsSavings.balancemomsSavings.balance = newBalance; = newBalance;

Designing and Implementing Designing and Implementing a Classa Class

1. What are you asked to do with an object, 1. What are you asked to do with an object,

list of operations needed.list of operations needed.

2. Find names for the methods.2. Find names for the methods.

3. Document the public interface.3. Document the public interface.

4. Determine instance variables.4. Determine instance variables.

5. Determine constructors.5. Determine constructors.

6. Implement methods one at a time, easiest 6. Implement methods one at a time, easiest first.first.

7. Test class, apply method calls.7. Test class, apply method calls.