Re: Thinking in OO
- From: "Bernard Notarianni" <bernard.notarianni@xxxxxxxxx>
- Date: 30 Apr 2006 10:02:51 -0700
Greg,
I learned OOP thank to Smalltalk and this book:
http://bookshelved.org/cgi-bin/wiki.pl?SmalltalkObjectsAndDesign
The first lesson from this book is to think about objects as
"homunculus" which means "small human" in Latin. A main task
while designing an OO program is inventing a language to talk to the
objects. This language, composed of the classes and methods names,
should be human readable and easy to understand.
To me, your turn.left, turn.right and so on are ok. They are clear and
easy to understand.
I like very much also your "attack" or "evade" thinks, but they
are maybe other objects. They might be seen as strategies that could be
applied to robots. Hence, you could have Strategy objects given to your
robot and guiding their behavior by sending them lists of commands
turn.rigt, turn.left etc... Strategy could be an abstract class with
several inherited classes such as AttackingStrategy, DefendingStrategy
and so forth.
Robot r2d2 = new Robot()
r2d2.adoptStrategy(new AttackingStrategy())
Again, always try to have the best word to name your classes and
methods. I am not sure that Strategy is the best name here. Do not
hesitate to give a better name if you find one (such as Behavior? or
Tactic?) Trying to give good names to classes and methods is never
over-analysing IMHO.
Hope that help,
Bernard.
.
- References:
- Thinking in OO
- From: Gregory Coit
- Thinking in OO
- Prev by Date: Re: Alien design paradigm to alleviate "software crisis"
- Next by Date: Re: Managing multiple instances
- Previous by thread: Re: Thinking in OO
- Next by thread: native arrays in class diagrams
- Index(es):
Relevant Pages
|