Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Classes and OO

Name: Anonymous 2007-09-02 21:13 ID:DbhLNVSF

I'm not the greatest programmer ever, I'll brute force if I have to, and any professional programmer would probably cringe in horror at some of my code.  Just a small disclaimer.  I'm currently using a Java derivative language (Processing), and hence Object Oriented.  My question is, is there some kind of guideline for when a new class is or isn't a good idea? How do you know when you're over or underusing classes vs. new methods.

Name: Anonymous 2007-09-02 21:24 ID:6q6MGSSQ

>>1
most people don't know. just use common sense. the only good advice I guess I can give is, if you have a set of classes whose behaviour depends too much on the behaviour of the other classes, you're doing it wrong. For example, most stuff like this:

objectA.propertyB.methodC()

is wrong. Why? because propertyB is also an object, and maybe someday objectA will stop having propertyB. Yes, I know this sounds a bit too much like "enterprise scalabe programming", but actually it's not, it's about proper abstraction (SICP). So instead just write something like
methodD() {self.propertyB.methodC }

and then write

objectA.methodD()

You'll notice when following this guideline, it's easier to break down classes into two or adding up classes if needed.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List