Am 30.01.2013 20:11, schrieb dennis luehring:
Am 30.01.2013 19:58, schrieb Paulo Pinto:
Am 30.01.2013 18:18, schrieb dennis luehring:
in real OOP objects are specialized through its virtual method
implementations AND its ctor-parameters (which are similar in very very
few rare cases)
for example pseudo code
class Stream
virtual read_bytes()...
class FileStream: Stream
this(filename)
class NetworkStream: Stream
this(tcp_ip,timeout)
Stream[] streams
streams ~= FileStream("c:/temp/test.txt");
streams ~= NetworkStream("123.112.2.1", 1000);
stream[n].read_bytes()
this is a much more common OOP/ctor situation then yours
i think its part of pascal/object delphi to ease the VCL development
but this can be easily reached with an internal CreateInstance
routine like
Stream
virtual Stream CreateInstance()
and
FileStream implements CreateInstance() with with return new
FileStream
NetworkStream "" with new NetworkStream etc.
so whats the realy big deal/feature of this "class of"-type except for
very trivial OOP case
Actually there are many definitions what real OOP means.
As for Delphi's case, if I am not mistaken it tries to follow the
metaclass concept that Smalltalk has, and Java/.NET have to a certain
extent.
no there aren't many definitions but many many missuse of the concept
Well, Smalltalk, Simula, C++/Java/C#, OCaml, CLOS, JavaScript, BETA,
Modula-3, Eiffel, Ada, Sather, and many others. All have different
concepts what OO should really be.
Enough material to write a few OOPSLA papers I would say.
you interface is the adaptor, your virtual method code is the special
behavior, your ctors parameters are the intialisers of the special
behavior - everything else is just a pseudo-procedural style - its not
OOP if you need to use casts and ifs on your object-type, thats
procedural programming with class-based fake-namespaces
There I agree with you. Casts should only be a kind of last resort and
are mostly a sign of bad design.
can you give me a small example of the metaclass concept of smalltalk -
related to my simple stream example?
Your simple example was correct, as this is not the use case of
metaclasses. Maybe my post was a bit off topic.
In case you are not familiar with the concept, in Smalltalk everything
is an object. Every object is of course represented by a class
description and you create instances of the said classes.
Additionally each class also has a class that represents it. In a simple
description it allows to manipulate the set of methods, instances and
other information that represents the real class.
It is also the container for what is known as static methods/variables
in other languages.
However, given Smalltalk's dynamic behavior, you can on the fly change a
class's metaclass and with it simulate multiple inheritance, method call
delegation or other tricks.
If I am not mistaken, Objective-C and Ruby allow similar tricks, given
their Smalltalk influence.
--
Paulo