P
Phlip
Ioannis said:An example in .NET is
int x;
String *p= x.ToString();
That is a related topic: "Everything is an object, so you can extend even
systemic primitives like integers. You can inherit the int class and even
add new methods to the global int class."
What is the benefit of having classes being objects? May you provide an example?
Are you talking about RTTI?
(getting a touch of deja-vu here...)
I mean the Prototype Pattern is built-into languages where classes are
objects.
def foo(klass)
objekt = klass.new()
...
end
That's it. Foo() can build and use an object of any type you pass in
(including Foo(int)), so long as objekt obeys whatever interface the
ellipses ... demand from it.
When refactoring to merge duplication, this technique can allow a lot to
vanish into abstracted constructors. Confer: Construction Encapsulation.
When refactoring to merge such duplication in C++, you have the odious and
expensive choice of a template, which afflicts all your downstream code.
Hence, libraries like Boost must make everything a template of a template of
a template. Yes, it's efficient, but that's only because the 'template'
keyword was retrofitted into existing compiler technology.