On 02.06.2007 18:02, Trans wrote:
class Bar < Base
I’d rather call this “namespace” because that’s what the module is all
about here. IMHO this is the best approach for custom libs because it
helps keep namespaces clean. Also, if someone is using classes from
this module only, it’s easy to place an include Foo at the top of the
script to pull all classes defined in Foo into the current namespace.
IMHO that’s the worst of all presented approaches because it combines
two mechanisms that create dependencies between classes (inheritance and
nesting) that support different aims. I’d use nesting for classes that
are closely related to the outer class and make most sens in this
connection. Inheritance (besides delegation) is the usual way to extend
classes, probably even from another module / lib.
class Bar < Foo
I haven’t seen this one and would not do it because it does not ensure
proper use of namespaces.
- BY NAME
No container modules, just use naming:
class BarFoo < Foo
I would not use this one in a custom lib because namespaces are really a
better grouping mechanism than name suffixes. Even if you use BarFoo as
subclass name I’d rather do it in a module.
Which is better? Are there serious advantages/disadvantages to any of
There are probably more pros and cons but when I would be writing a lib
I’d certainly use the first approach.