Classes / Objects / MethodsObject Oriented ProgrammingClassSlide 4ObjectsDog ObjectMethodsParametersLevels of MethodsCreate New MethodSlide 11Add Method InstructionsCalling a MethodSlide 14Slide 15Create Method with ParameterCreating ParameterParameterUse Parameter in MethodCalling Method with ParameterMultiple ParametersModify Method CallCreate Another MethodHomeworkClass MethodsGuidelines for Class MethodsInheritanceCreating a New Class in ALICERename ObjectSave As New ClassNew ClassSlide 32Classes / Objects / Classes / Objects / MethodsMethodsChapter 4Chapter 4Object Oriented ProgrammingObject Oriented ProgrammingDivides a program into Divides a program into Modules/ClassesModules/ClassesUses Classes and Objects to simulate Uses Classes and Objects to simulate real world environmentsreal world environmentsBasic Programming ComponentsBasic Programming Components•ClassesClasses•ObjectsObjects•MethodsMethodsClassClassSpecifies the definition of a particular Specifies the definition of a particular kind of objectkind of object•FrogFrog•SnowmanSnowman•Cell phoneCell phoneBlueprint / design for how to create Blueprint / design for how to create an object of that typean object of that typeClass names begin with a Capital Class names begin with a Capital letterletterClassClassPropertiesProperties•CharacteristicsCharacteristicsMethodsMethods•BehaviorsBehaviorsObjectsObjectsSpecific Instances of a ClassSpecific Instances of a ClassImplementation of the Class DefinitionImplementation of the Class Definition•Spot Spot one specific dog one specific dog•Frosty Frosty one specific snowman one specific snowmanAll specific objects of the same class share All specific objects of the same class share the same definitionthe same definition•Same Properties – can be modifiedSame Properties – can be modified•Same Methods – can be modifiedSame Methods – can be modifiedObject names begin with lowercase letterObject names begin with lowercase letterDog ObjectDog ObjectAll Instances of Class All Instances of Class Dog HaveDog Have•PropertiesPropertiesNameNameBreedBreedWeightWeightColorColor•MethodsMethodsWalkWalkBarkBarkJumpJumpEach Instance HasEach Instance Has•PropertiesPropertiesSpotSpotMuttMutt10 pounds10 poundsBlackBlack•MethodsMethodsWalkWalkBarkBarkJumpJump(can be modified to fit (can be modified to fit Spot’s requirements)Spot’s requirements)MethodsMethodsSequence of InstructionsSequence of InstructionsTasks that can be performedTasks that can be performedSome are predefined within the ClassSome are predefined within the Class•Dog has a bark methodDog has a bark methodOthers are Created or ModifiedOthers are Created or ModifiedMethods organize the programMethods organize the program•Divide the program into manageable Divide the program into manageable piecespiecesParametersParametersPieces of Information that need to be Pieces of Information that need to be sent to the Method sent to the Method Turn Toward (what)Turn Toward (what)Turn Toward SnowwomanTurn Toward SnowwomanLevels of MethodsLevels of MethodsGlobal Methods (World Level)Global Methods (World Level)•Methods that reference more than one Methods that reference more than one objectobjectClass MethodsClass Methods•Methods that define a behavior for one Methods that define a behavior for one single objectsingle objectCreate New MethodCreate New MethodSnowpeople (problem 4-1)Snowpeople (problem 4-1)•flipsHatflipsHatRaises right armRaises right armGrabs HatGrabs HatTips toward snowwomanTips toward snowwomanReturns Hat to HeadReturns Hat to HeadWorld Method World Method •Uses snowman and snowwomenUses snowman and snowwomen•WorldWorld•MethodMethod•Create New MethodCreate New Method•Name Name flipsHat flipsHatAdd Method InstructionsAdd Method InstructionsCalling a MethodCalling a MethodNew Method must be “Called”New Method must be “Called”Program Instructions must indicate to Program Instructions must indicate to Execute the new MethodExecute the new MethodIn AliceIn Alice•Drag Method into World.MyFirstMethodDrag Method into World.MyFirstMethodIn Other LanguagesIn Other Languages•Call the Method using Method NameCall the Method using Method NameParametersParametersAllows communication with MethodsAllows communication with Methods•Communicate Values (Numbers, Colors)Communicate Values (Numbers, Colors)•Communicate Object NamesCommunicate Object NamesCreate Method with ParameterCreate Method with ParameterCreate Method called “dance”Create Method called “dance”•Object will jump up and down and spin aroundObject will jump up and down and spin aroundCreate ParametersCreate Parameters•Parameter 1Parameter 1Which object to danceWhich object to dance•Parameter 2Parameter 2 How many times to SpinHow many times to SpinCreating ParameterCreating ParameterWhich object to DanceWhich object to Dance•NameNameArbitrary Arbitrary Placeholder – holds place of the actual Placeholder – holds place of the actual object the will be used in the method object the will be used in the method •Type:Type:NumberNumberBoolean (True/False)Boolean (True/False)ObjectObjectOther (Sound, Color, Etc.)Other (Sound, Color, Etc.)ParameterParameterParameters show in Upper Left of Method Parameters show in Upper Left of Method PanelPanelWhen Method is Called (Used)When Method is Called (Used)•Object must be sent as an Argument to Method Object must be sent as an Argument to MethodUse Parameter in MethodUse Parameter in MethodCalling Method with ParameterCalling Method with ParameterWhen using Method you must include When using Method you must include ParameterParameterUse dance method after flipHatUse dance method after flipHatExample 1: Requires an object to Example 1: Requires an object to dancedanceMultiple ParametersMultiple ParametersAdd Second Parameter – How many Add Second Parameter – How many times to Spintimes to Spin•Name: numberToSpinName: numberToSpin•Type: NumberType: Number•Use in the Turn InstructionUse in the Turn InstructionModify Method CallModify Method CallChange 2Change 2ndnd Parameter Parameter Pick any 2 different numbersPick any 2 different numbersCreate Another MethodCreate Another MethodCreate a Method for
View Full Document