http://www.perlmonks.org?node_id=414253


in reply to Advice on OO Program structure & organization

OO is not just design, OO is for reusability. So, don't write any read and write methods, just use another Class/Module that already exists, in this case IO::All, and call it:
use Class::HPLOO ; class Foo { use IO::All ; ## Object initializer: sub Foo ($file) { $this->{file_data} < io($file) ; } }
Class::HPLOO is just a module that enables this kind of OO syntax for Perl. But I recommend to learn the pure Perl style, since with it you are free to do anything. But this style above save me a lot of time. ;-P

Graciliano M. P.
"Creativity is the expression of liberty".

Replies are listed 'Best First'.
Re^2: Advice on OO Program structure & organization
by Anonymous Monk on Dec 13, 2004 at 17:08 UTC
    This is bad for many reasons, namely you have no way of instantiating a Foo without using a file, in this case. There is nothing wrong with adding functions for read/write, as this is common in serialization idioms (they'll even call other methods of child objects, etc).

    As the more versed in softare design will know, using an existing module has nothing to do with OO, nor does OO have anything to do with reusability. It is commonly parroted that non-OO code is not reusable, and it may better be said that non-namespaced code is not reusable. It has nothing to do with object-orientation. Structure-oriented code can easily handle reuse, OO when yielded properly has greater advantages of course -- such as polymorphism.

      The code above is just an example! duh! About OO and reusability. Well, OO doesn't guarantee reusability, but I dare you to make good reusability without OO.

      Graciliano M. P.
      "Creativity is the expression of liberty".

        Oh, I don't know, let's say ... umh ... the Linux kernel?

        Most functional programming, such as Lisp/Scheme, also eclipses OO code reuse ... many times over.