[fpc-pascal] Implementing Factory Method with Pascal

Marcos Douglas md at delfire.net
Mon Nov 30 01:23:35 CET 2015


On Sun, Nov 29, 2015 at 6:17 AM, Michael Van Canneyt <michael at freepascal.org>
wrote:
>>
> First of all, inheritance is inherent in object oriented programming,
since
> every object descends from a base object.
> So saying that 'inheritance must die' is a stupid sentence or title for a
> blog.

Now I see what's happened.
My laziness made me just point to two links, because I did not want to
write a complete example. I should have said before:
1- Inheritance is evil, be careful, use it wisely -- fast food is evil too,
but I eat (sometimes) anyway.
2- I prefer composition instead inheritance because it's more simpler to
use and understand.
And the most important (for me):
3- Composition is not about only 'has a' construction, but more about
Decorator design pattern.

IMHO Decorators are more flexible to add features than use sublcasses.

> - Composition results in slower code (1), since the program must always
> dereference and fetch an extra object.
>
> - Composition results in more memory being used. Inheritance puts
everything
> in 1 block: parent+child.
> Composition uses 2 blocks, plus a pointer to connect the two. Every memory
> block introces an extra area.
> If you have a really bad designed hierarchy, then the 'child' object needs
> an extra pointer to the 'parent'.
> Again extra memory.
>
> - Composition results in slower code (2) because the extra memory blocks
> must be managed.

Performance and memory, of course.
Well, my priorities are design, simplicity and manutenability. I think
we're both right, just depends of contexts and priorities.

> You can argue that this is irrelevant these days: well, it is relevant,
> because the effect of this is exponential, not linear.

Yeah, I think like that in most cases, but you're right when says this is
exponential problem. Not all problems can be solved with pure object
orientation, of course, and that is the reason we have hammer and saw.

> Not a technical argument, but nevertheless: If you think about it,
> composition is just some syntactic sugar for procedural programming, just
as
> they do in C.

I don't understand why do you think this.

> I thought it was obvious that my joke was aimed at the authors of the web
> pages you posted, not at you.
> Most likely, they were frustrated by having to use wrongly designed
classes.

As I said above, I should had written my examples or have explained more my
thoughts, but I didn't. My fault. Nevertheless you wrote for me, so I think
the joke wasn't just for the links but for the general context, ie, what I
said plus links.

> If I have offended you, I apologize for that, this surely was not my
> intention.

I appreciate that. No problem. Let's put a rock in this debate and move on.
Thanks.

Marcos Douglas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20151129/7fe7e716/attachment.html>


More information about the fpc-pascal mailing list