On Jan 12, 2004, at 5:27 AM, Gary Stainburn wrote:

Hi folks,

Hello again.


I'm after peoples opinions on my (beginner's) slant objects in perl.

I'll see what I can do.


In much of what I've read, there seems to be the implied rule that

Package Name == Class == Object Type,

specifically MyObject would be a object of class MyObject which would be held
in a package MyObject, and would probably be created by calling
MyObject->new.

You seem to be getting it just fine to me.


In my Package Trainset, I have class Trainset with variables global to that
class. However, I don't have an object type of Trainset

Well, then it's not really a "class" is it? It's just a package or a namespace, if you will.


(In a previous thread someone suggested creating one to hold the class variables instead of using globals, to enable me to create more than one trainset. I decided that
would create more problems than it would solve here).

Create more problems than it solves? Pardon the pun, but I think your logic just derailed. ;)


I recall a big discussion on this list when we saw your code about what that external hash in the constructor was and if it was a good idea to be manipulating things like that. If nothing else, I think we can assume from this that the intent of the code is not crystal clear. That means you stand to gain readability by objectifying Trainset.

The suggestion was made, as you note above, because the code would gain functionality from the change as well.

That's two plusses, what do you stand to lose?

I do have object types:

* Block
* point (switch to american readers)
* signal
* lever
* signalbox

These are all created by calling Trainset->Block etc., and the code for all
object types are in the Trainset package.


My question is:

Is there anything wrong with what I'm doing, or any pit-falls I need to watch
out for?

I would prefer and I think it would be better OO design if the classes where broken out into separate modules. Maybe something like:


Trainset.pm
Trainset/Block.pm (package Trainset::Block)
Trainset/Point.pm (package Trainset::Point)
Trainset/Signal.pm (package Trainset::Signal)
Trainset/Lever.pm (package Trainset::Lever)
Trainset/SignalBox.pm (package Trainset::SignalBox)

Is there a better way to do this, without further complicating or slowing of
the code (e.g. indirect access to the globals via Trainset methods as would
be needed if I created a Trainset object)?

I'm not sure if I totally understand the complaint above, but let me see if I can change your thinking anyway... :D


I was envisioning Trainset as the interface object to outside code. I wouldn't think a user would be wanting to call those five extra constructors and attach the new object to the right part of the Trainset. I would think they would call something like $trainset->add_signal(SOME PARAMS HERE) and the Trainset object would handle all the gory details, including creating the Signal object.

Does that give you any new ideas?

I should probably say that I know very little about what you're trying to create here and even less about trains, so if I'm being dumb, just ignore me. I'm just trying to toss out some general ideas.

Good luck.

James


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to