From: SZMURLO MAURICE Date: 2001-01-08T16:35:59+09:00 Subject: [ruby-talk:8831] Re: abstract classes This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_001_01C07944.FCDF17F0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit Hi, I was mainly thinking about abstract in the java sense: non-instatiable classes with methods that are to be implemented in subclasses: something like: class Employee def-abstract-method work; ... other ... end class Worker << Employee def work # do the worker job end ... other ... end class << Secretary # work not impemented ... other end 1. Worker.new(...).work #-> OK 2. Secretary.new(...).work #-> Error: abstract mathod "work" not implemented 3. Employee.new(...) #-> Error: cannot instatiate abstract class I know that "work" could be implemented in Employee with an exception thrown. This would solve case 2, but still an Employee could be instantiated (3.), which conceptually is not a good thing. Is the solution to declare Emplyee as a module? maurice # # >is there any way to declare abstract classes/methods in ruby? # # It depends on what you mean by abstract classes. # You can prevent people from invoking a new # operator by making it a protected method. # # Can you give an example of what you would like to # accomplish? # # Kevin # ------_=_NextPart_001_01C07944.FCDF17F0 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 7bit RE: [ruby-talk:8754] Re: abstract classes

Hi,

I was mainly thinking about abstract in the java sense:
non-instatiable classes with methods that are to be
implemented in subclasses:

something like:

class Employee
  def-abstract-method work;
  ... other ...
end

class Worker << Employee
  def work
    # do the worker job
  end
  ... other ...
end

class << Secretary
  # work not impemented
  ... other
end

1. Worker.new(...).work    #-> OK
2. Secretary.new(...).work #-> Error: abstract mathod "work" not implemented
3. Employee.new(...)       #-> Error: cannot instatiate abstract class

I know that "work" could be implemented in Employee with an exception thrown.
This would solve case 2, but still an Employee could be instantiated (3.), which
conceptually is not a good thing.

Is the solution to declare Emplyee as a module?

maurice

#
# >is there any way to declare abstract classes/methods in ruby?
#
# It depends on what you mean by abstract classes.
# You can prevent people from invoking a new
# operator by making it a protected method.
#
# Can you give an example of what you would like to
# accomplish?
#
# Kevin
#

------_=_NextPart_001_01C07944.FCDF17F0--