in reply to RE (tilly) 1: Object Heirarchy / Design
in thread Object Heirarchy / Design

This brings up some other questions that I forgot to bring up.

  1. How should logging be handled from these input classes? Obviously, they should all log through a standard interface, but due to the fact that they're not direct subclasses, I can't simply call $self->log( $msg ) or anything like that.
  2. If there is an object hierachy such as follows:
    package Obj; package Obj::Input; @ISA = 'Obj'; package Obj::Input::Type; @ISA = 'Obj::Input';
    then Obj::Input::Type is inheriting from Obj, which doesn't make sense, since Obj::Input::Type isn't an Obj. But it should have access to some of the 'utility' functions provided by Obj. Those utility functions should somehow be provided by Obj::Input, which should also definitely by in Obj::Input::Type's @ISA.
    phew.

Replies are listed 'Best First'.
RE: RE: RE (tilly) 1: Object Heirarchy / Design
by btrott (Parson) on Nov 15, 2000 at 07:53 UTC
    As tilly wrote: Obj::Input::Type doesn't need to inherit from Obj. If those "utility" functions are needed by both Obj::Input::Type and Obj, then they should be broken out of Obj and moved into their own utility class.

    I don't know what your "utility" methods are (perhaps you mean logging, etc.), but my personal preference is this: if from a logical perspective it doesn't make sense to have them methods of Obj, then they shouldn't be declared as methods of Obj. In my opinion, it doesn't make sense for an Obj to have a "log" method. Why should it? How is "log" acting on, or acting with, or have anything to do with an Obj object? I don't think it does. If you come at it from that perspective, I think it may be a bit clearer what methods belong in what classes.

RE (tilly) 3: Object Heirarchy / Design
by tilly (Archbishop) on Nov 15, 2000 at 07:13 UTC
    Why would Obj::Input bother inheriting from Obj? What does either Obj or Obj::Input get from this?

    Think about your classic diagrams with Dog and Cat inheriting from Animal. Well Animals generally contain four instances of Leg, that doesn't mean that a Leg is an Animal though!

    Instead Obj::Input exists for the purpose of containing useful utility methods for drivers to use. Your Obj class just assumes the interface it needs will work.

    As for logging (if you want it), provide a logging method in your base class, then you do just call the method.