ICM class 4

22
ICM class 4 Functions and Objects

description

ICM class 4. Functions and Objects. Functions. Modularity. Functions. Modularity Reusability. Functions. Functions. ReturnType functionName (arguments){ } OutputType functionName (Input){ return output; }. Functions. int square(int number){ return number * number; }. Functions. - PowerPoint PPT Presentation

Transcript of ICM class 4

Page 1: ICM class 4

ICM class 4

Functions and Objects

Page 2: ICM class 4

Functions

• Modularity

Page 3: ICM class 4

Functions

• Modularity• Reusability

Page 4: ICM class 4

Functions

Page 5: ICM class 4

Functions

ReturnType functionName (arguments){

} OutputType functionName (Input){

return output;}

Page 6: ICM class 4

Functions

int square(int number){return number * number;

}

Page 7: ICM class 4

Functions

Setup and draw… void

Page 8: ICM class 4

Objects – Part 1

• Encapsulation• Modularity

Page 9: ICM class 4

Encapsulation

• An object is a bundle of variables, statements and functions

Page 10: ICM class 4

Encapsulation

Page 11: ICM class 4

Encapsulation

class Car{//declare propertiesCar(){

//init properties}//declare more methods

}

Page 12: ICM class 4

Encapsulation

Car car1;void setup(){

car1 = new Car();}void draw(){

car1.doSomething();}

Page 13: ICM class 4

Encapsulation

• Lets try it together

Page 14: ICM class 4

Encapsulation

Makes it easy to have more than 1

Page 15: ICM class 4

Encapsulation

• Conceals the functional details

Page 16: ICM class 4

Modularity

• Independent components

Page 17: ICM class 4

Objects – Part 2

• Inheritance• Overloading

Page 18: ICM class 4

Inheritance

• Animals, cats and dogs… and elephants and giraffes, and goldfish!

Page 19: ICM class 4

Inheritance

class Animal{Animal(){}

}class Cat extends Animal {

Cat(){super();

}}

Page 20: ICM class 4

Overloading

• Same function name + different arguments• Ie. fill(255);• fill(255,123,0);• fill(255,123,0,115);

Page 21: ICM class 4

Why OOP

• Easier updating• Easier debugging• Easier sharing• Reusable maintainable code

Page 22: ICM class 4

Why OOP

• You don’t want to be like this guy