110 likes | 123 Views
Discusses OOP terminology, syntax, constructors, and methods in Jeroo. Explains how objects are defined, their properties, and methods. Covers classes, creating objects, and sending messages to objects. Provides examples and emphasizes the importance of syntax.
E N D
Overview • In this presentation we will discuss these topics: • OOP terminology • Jeroo syntax • constructors • methods
OOP syntax • Object oriented programming defines objects • Each Jeroo you create is an object. • an object has properties • For example: • a Jeroo has a location • number of flowers in its pouch • a direction it is facing • an object has methods (things it can do) • a Jeroo can hop, pick, plant and toss. these properties must be set to an initial value when the Jeroo is created, and change as the Jeroo acts.
Classes = definitions of objects • When you create a new object it is constructed. • An object may be constructed a number of different ways. this is the default constructor
Classes • A class describes 3 things: • What kind of data is in an object • Example: a Jeroo object contains three types of information: • its location, • its direction, • and the number of flowers in its pouch. • How to make a new object of that class • Example:Jeroo andy =new Jeroo(2,5,SOUTH,3); • Location = row 2, column 5 • Direction = SOUTH • Holding 3 flowers • The default constructor creates a Jeroo at location 0,0 facing EAST with no flowers • Jeroo andy =new Jeroo(); • The methods of an object (the actions it can perform) • Example: andy.hop(); • Jeroos can hop, pick flowers, plant flowers, toss flowers into nets, give flower to another Jeroo, and turn.
Syntax is important! • A class is the type of an object • Each object that is created is named • Jeroo andy =new Jeroo(2,5,SOUTH,3); • andy is an object • Jeroo is the class
Sending messages to objects • After objects are created, they are given directions • This is called sending a message to the object • A message looks like this: • object.method(extra information); • The object is the thing we are talking to • The method is a name of the action we want the object to take • The extra information is anything required by the method in order to do its job (also called a parameter) • Examples: andy.turn(RIGHT); susanna.toss(); no extra information needed
Messages and methods • Messages can be used to: • Give an object some information • Tellan object to do something • Askan object for information (usually about itself) • Any and all combinations of the above • A method is something inside the object that responds to your messages • A message contains commands to do something
Using OOP syntax • Rewrite the following English statements as object oriented messages • Tell the woman named Clarissa to walk 2 steps • Clarissa.walk(2); • Tell the Jeroo named Alan to turn to the right • Alan.turn(RIGHT);
Vocabulary Review • class: the type, or description, of an object • Jeroo classes are descriptions of: • island, water, flower, net, jeroo • constructor: a way to create an object. comes as part of the class definition. • object: an instance, or member, of a class • You can only create Jeroos in your code, all other objects must be created visually. • message: something that you “say” to an object, either telling it something or asking it for information • parameter: information sent to a method