Week 3 Workshop

techBoyClass

EmergingTech Boy Class – Using class objects

1) Fundamentals in Object-Oriented Programming (OOP)

Objectoriented programming (OOP) is a programming paradigm based on the concept of “objects“, which are data structures that contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods. (wikipedia)

Explanations from https://processing.org/tutorials/objects/
The following is an example of what you would put in the ‘main’ in your sketch. 🙂

// Step 1. Declare an object.
Car myCar;

void setup()  {    
  // Step 2. Initialize object.
  myCar = new Car();   
}    

void draw()  {    
  background(255);  
  // Step 3. Call methods on the object. 
  myCar.drive();   
  myCar.display();   
}

2) Constructor in class:
constructor is a function that instantiates a particular type of Object. You invoke a constructor with the new keyword.

A class can have multiple constructors that assign the fields in different ways. Sometimes it’s beneficial to specify every aspect of an object’s data by assigning parameters to the fields, but other times it might be appropriate to define only one or a few. (procession.org)

See the image from https://processing.org/tutorials/objects/

constructor_arguments

class

Resources:
https://processing.org/tutorials/objects/

http://www.learningprocessing.com/examples/chapter-8/example-8-2/

https://processing.org/examples/multipleconstructors.html

 

 

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s