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.
------_ extPart_001_01C07944.FCDF17F0
Content-Type: text/plain;
charset o-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
#
------_ extPart_001_01C07944.FCDF17F0
Content-Type: text/html;
charset o-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV
ontent-Type" CONTENT ext/html; charset o-8859-1">
<META NAME enerator" CONTENT S Exchange Server version 5.5.2651.75">
<TITLE>RE: [ruby-talk:8754] Re: abstract classes</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE Hi,</FONT>
</P>
<P><FONT SIZE I was mainly thinking about abstract in the java sense:</FONT>
<BR><FONT SIZE non-instatiable classes with methods that are to be </FONT>
<BR><FONT SIZE implemented in subclasses:</FONT>
</P>
<P><FONT SIZE something like:</FONT>
</P>
<P><FONT SIZE class Employee</FONT>
<BR><FONT SIZE def-abstract-method work;</FONT>
<BR><FONT SIZE ... other ...</FONT>
<BR><FONT SIZE end</FONT>
</P>
<P><FONT SIZE class Worker << Employee</FONT>
<BR><FONT SIZE def work</FONT>
<BR><FONT SIZE # do the worker job</FONT>
<BR><FONT SIZE end</FONT>
<BR><FONT SIZE ... other ...</FONT>
<BR><FONT SIZE end</FONT>
</P>
<P><FONT SIZE class << Secretary</FONT>
<BR><FONT SIZE # work not impemented</FONT>
<BR><FONT SIZE ... other</FONT>
<BR><FONT SIZE end</FONT>
</P>
<P><FONT SIZE 1. Worker.new(...).work #-> OK</FONT>
<BR><FONT SIZE 2. Secretary.new(...).work #-> Error: abstract mathod "work" not implemented</FONT>
<BR><FONT SIZE 3. Employee.new(...) #-> Error: cannot instatiate abstract class</FONT>
</P>
<P><FONT SIZE I know that "work" could be implemented in Employee with an exception thrown.</FONT>
<BR><FONT SIZE This would solve case 2, but still an Employee could be instantiated (3.), which</FONT>
<BR><FONT SIZE conceptually is not a good thing.</FONT>
</P>
<P><FONT SIZE Is the solution to declare Emplyee as a module?</FONT>
</P>
<P><FONT SIZE maurice</FONT>
</P>
<P><FONT SIZE # </FONT>
<BR><FONT SIZE # >is there any way to declare abstract classes/methods in ruby?</FONT>
<BR><FONT SIZE # </FONT>
<BR><FONT SIZE # It depends on what you mean by abstract classes. </FONT>
<BR><FONT SIZE # You can prevent people from invoking a new </FONT>
<BR><FONT SIZE # operator by making it a protected method.</FONT>
<BR><FONT SIZE # </FONT>
<BR><FONT SIZE # Can you give an example of what you would like to </FONT>
<BR><FONT SIZE # accomplish?</FONT>
<BR><FONT SIZE # </FONT>
<BR><FONT SIZE # Kevin</FONT>
<BR><FONT SIZE # </FONT>
</P>
</BODY>
</HTML>
------_ extPart_001_01C07944.FCDF17F0--