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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

320<br />

One of the benefits of data hiding is that dependencies between properties can be better<br />

managed. For example, if an object uses the values of a number of properties to calculate<br />

something, <strong>and</strong> users are allowed to go in willy-nilly <strong>and</strong> change any property values<br />

directly, calculations could be adversely affected. However, if you use a method, property<br />

values can be both set <strong>and</strong> checked prior to performing any calculation, improving upon<br />

both program efficiency <strong>and</strong> reliability.<br />

All that being said, in <strong>Processing</strong>, everything is public by default, meaning that to a user of<br />

the <strong>Processing</strong> API, everything is directly accessible. This design decision was made to keep<br />

<strong>Processing</strong> as simple as possible. However, it is possible, especially when working in Java<br />

mode, to make your properties private <strong>and</strong> enforce data hiding. In Chapter 14, you’ll work<br />

in Java mode, making your object properties private <strong>and</strong> using public get <strong>and</strong> set methods<br />

to interact with them. To learn more about this concept, check out http://java.sun.com/<br />

docs/books/tutorial/java/concepts/object.html.<br />

Inheritance<br />

Inheritance in OOP is the ability of a class A to inherit or extend another class, B, enabling<br />

class A to have access to the properties <strong>and</strong> methods within the extended class B. In this<br />

constructed relationship, class B is referred to as the superclass that class A extends, <strong>and</strong><br />

class A becomes the subclass that extends class B. In addition, class A can add its own additional<br />

properties <strong>and</strong> methods, <strong>and</strong> even overwrite specific properties <strong>and</strong> methods of<br />

class B (its extended superclass). Inheritance proceeds in a general-to-specific direction.<br />

For example, if I have a class called GermanShepherd, I could start with a very general base<br />

class, called Mammal, a subclass of Mammal called Quadruped, a subclass of Quadruped called<br />

Canine, <strong>and</strong> a subclass of Canine called GermanShepherd. A Feline class could also inherit<br />

from Quadruped, while a Human class might come from a Biped class that inherited from<br />

Mammal. Figure 8-1 shows a diagram of this.<br />

Figure 8-1. OOP inheritance diagram

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

Saved successfully!

Ooh no, something went wrong!