Good OOP Practice

BlitzMax Forums/BlitzMax Beginners Area/Good OOP Practice

Ant(Posted 2005) [#1]
Hi, more a good practice question, and possibly irrelevent! For examples sake, say I wanted to create a button which you click using OOP/types etc

Say I have defined a type with a list of fields for that button (lets say name,x,y). And say I have created a method CreateButton for that type.

The question I have is this. Is it ok practice to pass the parameters of the button through the createbutton method to initialise it and set the fields for that button, or do people tend to access the fields using the (nameofobject).field way. Or, doesn't it matter!?

I know this is an odd question, jsut want to get into good habits!

cheers


Who was John Galt?(Posted 2005) [#2]
Usually you have functions to set the fields - this allows you to change the internal implementation without changing the interface - but its a bit slower and not always necessary. Matter of choice I would say.


bradford6(Posted 2005) [#3]
pick up a copy of head first design patterns

the examples are in Java but fairly easy to translate into BMAX


it is an excellent book on OOP. very fun to read and easy to follow as well.


jhague(Posted 2005) [#4]
The best rule of thumb: Whatever is simpler for you to work with. In this case, I'd say it's fine to pass the parameters through the initialization function.


FlameDuck(Posted 2005) [#5]
The question I have is this. Is it ok practice to pass the parameters of the button through the createbutton method to initialise it
This is fine.

do people tend to access the fields using the (nameofobject).field way.
This is less fine, although very common, particularly for people who don't work in an IDE that will automaticly create accessor/mutator methods and/or properties for you.


Ant(Posted 2005) [#6]
Ok guys, thanks very much for all the responses. Made my trip to Amazon and the book is en route. Appreciate all the help!