04.04.2013 Views

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

304<br />

Of course, within the BurritoRecipe class, there could be additional methods <strong>and</strong> properties<br />

relating, for example, to side dishes, calories, costs, <strong>and</strong> so on. In OOP, your class<br />

design decisions are not unlike decisions you would make in the real world if you really<br />

were to make, serve, sell, or eat a burrito.<br />

Before you actually create your BurritoRecipe class, have a look at the basic framework<br />

of a simple generic class:<br />

class ClassName {<br />

}<br />

// properties<br />

int property1;<br />

float property2;<br />

// constructors<br />

ClassName(){<br />

}<br />

ClassName(int prop1, float prop2){<br />

property1 = prop1;<br />

property2 = prop2;<br />

}<br />

// methods<br />

void setProperty1(int prop1){<br />

property1 = prop1;<br />

}<br />

int getProperty1(){<br />

return property1;<br />

}<br />

void setProperty2(float prop2){<br />

property2 = prop2;<br />

}<br />

float getProperty2(){<br />

return property2;<br />

}<br />

A class begins with the keyword class, followed by a legal identifier (the name) of the<br />

class. The naming of classes follows the same naming rules described in Chapter 3. The<br />

convention is to begin class names with a capital letter. When using a compound name (a<br />

name made up of multiple words), such as ClassName, you also capitalize the initial letter<br />

of any nested words. Following the class identifier is an open curly brace. The class is<br />

closed with a final terminating curly brace, at the very bottom of the class. Between the<br />

open <strong>and</strong> closed curly braces are the class’s properties, constructors, <strong>and</strong> methods.<br />

The properties are variables declared within the class with a data type, an identifier, <strong>and</strong> an<br />

optional initial value. (If you don’t assign an initial value, the properties are assigned

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!