220 likes | 340 Vues
This guide explores the fundamentals of functions and object-oriented programming (OOP), focusing on key concepts such as modularity and encapsulation. Learn how functions can enhance code reusability, with examples of return types and function definitions. Discover the power of encapsulation in creating classes, managing properties, and implementing methods. We also cover inheritance, method overloading, and the advantages of OOP in simplifying code management and updates. This resource is ideal for beginners and intermediate learners seeking to strengthen their programming skills.
E N D
ICM class 4 Functions and Objects
Functions • Modularity
Functions • Modularity • Reusability
Functions ReturnType functionName (arguments){ } OutputType functionName (Input){ return output; }
Functions int square(int number){ return number * number; }
Functions Setup and draw… void
Objects – Part 1 • Encapsulation • Modularity
Encapsulation • An object is a bundle of variables, statements and functions
Encapsulation class Car{ //declare properties Car(){ //init properties } //declare more methods }
Encapsulation Car car1; void setup(){ car1 = new Car(); } void draw(){ car1.doSomething(); }
Encapsulation • Lets try it together
Encapsulation Makes it easy to have more than 1
Encapsulation • Conceals the functional details
Modularity • Independent components
Objects – Part 2 • Inheritance • Overloading
Inheritance • Animals, cats and dogs… and elephants and giraffes, and goldfish!
Inheritance class Animal{ Animal(){} } class Cat extends Animal { Cat(){ super(); } }
Overloading • Same function name + different arguments • Ie. fill(255); • fill(255,123,0); • fill(255,123,0,115);
Why OOP • Easier updating • Easier debugging • Easier sharing • Reusable maintainable code
Why OOP • You don’t want to be like this guy