[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: Interfaces in Ruby
From:       "Robert" <bob.news () gmx ! net>
Date:       2003-01-03 12:33:09
[Download RAW message or body]


"Chris Gehlker" <canyonrat@mac.com> schrieb im Newsbeitrag
news:CACB6AEA-E176-11D6-A92E-000A27DA50C4@mac.com...
> There is no need to enforce the use of the factory method. What needs
> to be enforced is that the program cannot instantiate an instance of
> the cluster base class. This corresponds directly to the C++ case where
> their is no enforcement of a restriction on directly constructing a
> derived concrete class but there is enforcement of the "no
> instantiation of virtual classes" rule.
>
> >   3) Having a private constructor in Ruby doesn't make sense; this is
> >      the purpose of a Module (you can always instantiate a Class, but
> >      you can't always instantiate a Module)
>
> Having a private constructor makes sense for cluster base classes and
> singleton classes.
> > Perhaps if you provide a sample implementation it would be easier to
>
> I'll try and translate my drawing program from ObjC to Ruby.

suggestion:

class Shape
    def move ... end
    def resize ... end
    def bounding_rectangle() ... end

  private
    def initialize() raise "Cannot instantiate"; end

    def init()
      # initializations
    end
end

class Rectangle < Shape
  private
    def initialize()
      # don't 'super' here but:
      init()
    end

    def init()
      super
      # other initializations
    end
end

regards

    robert



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic