Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object-oriented Design in Processing

Similar presentations


Presentation on theme: "Object-oriented Design in Processing"— Presentation transcript:

1 Object-oriented Design in Processing
B. Ramamurthy Pages

2 The OO Concept When you write small programs functional decomposition or collection of function efficiently solve the problem When you solve complex problem with multiple objects interacting, a better and proven way to design the solution is using Object-oriented design (OOD). When you implement a OOD using an object-oriented programming language it is called a object-oriented program. We will study here the foundations of OOD and OOP.

3 Object-Oriented Principles
OOP Inheritance -- Hierarchy -- Reusability -- Extensibility -- Expressive power -- Reflects many real-world problems Polymorphism -- Many forms of same function Encapsulation (class) -- Information Hiding -- Interface and Implementations -- Standardization -- Access Control mechanisms (private /public etc.) 11/23/2018

4 What is an Object? Object-oriented programming supports the view that programs are composed of objects that interact with one another. How would you describe an object? Using its characteristics (has a ----?) and its behaviors (can do ----?) Object must have unique identity (name) : Basketball, Blue ball Consider a ball: Color and diameter are characteristics (Data Declarations) throw, bounce, roll are behaviors (Methods) 11/23/2018

5 Classes are Blueprints
A class defines the general nature of a collection of objects of the same type. The process creating an object from a class is called instantiation. Every object is an instance of a particular class. There can be many instances of objects from the same class possible with different values for data. 11/23/2018

6 Example objects Object References redRose class Rose blueRose class
11/23/2018

7 Bouquet Class Many instances of real bouquet objects of this Class
can be instantiated 11/23/2018

8 Elements of a Class class data declarations (variables, constants)
methods header body header statements modifiers, type, name variables, constants parameters repetition others selection assignment 11/23/2018

9 Class Structure class variables constants methods 11/23/2018

10 Defining Classes Syntax: class class_name { data-declarations
constructors methods } Constructors are special methods used for instantiating (or creating) objects from a class. Data declarations are implemented using variable and constant declarations. 11/23/2018

11 Operator new and “dot” new operator creates a object and returns a reference to that object. After an object has been instantiated, you can use dot operator to access its methods and data declarations (if you have access permissions). 11/23/2018

12 Example Ball Class Class is an object blueprint; you can create as many objects as you need from a class Objects have attributes/characteristics Objects have behavior/capabilities/operations/functions Need a function to create an object… called a constructor There can more than one constructor for a class depending on the parameters

13 Class Ball class ball { // attributes float x, y; //position color ballColor; float radius; // operations //constructor ball() { x = random(width); y = random(height); ballColor = color(255, 0, 0); radius = 25; }

14 Add display behavior void display() { noStroke(); fill(ballColor); ellipse(x,y,2*radius, 2*radius); } Lets see how this works. How to create a ball? Using its constructor: Example b1 = new ball();

15 Box Class Lets add a box class And create many balls in the box class.


Download ppt "Object-oriented Design in Processing"

Similar presentations


Ads by Google