[fpc-devel] Multiple inheritance

Kostas Michalopoulos badsectoracula at gmail.com
Fri Aug 25 21:46:56 CEST 2017


Yeah, that would be helpful for when you need to use a more compositive
approach and when you want an object to take on multiple roles (e.g. some
sort of mediator or controller). Currently you need to create subclasses
for every role but those classes are only use once with the mediator for a
single instance per mediator and have wrap them, manage them (since class
instances must always be pointers), etc and this is a lot of verbose
boilerplate code to avoid a limitation of the language. Interfaces help a
tiny bit but they are very limited since you cannot have something like
base roles that implement most of the generic functionality but leave
specializations to the subclasses.

On Sat, Aug 19, 2017 at 10:49 AM, Ondrej Pokorny <lazarus at kluug.net> wrote:

> On 19.08.2017 9:27, Sven Barth via fpc-devel wrote:
>
>> The designers of Object Pascal decided on purpose against multiple
>> inheritance as they probably saw the problems that C++ has with them. Even
>> Java and C#, both clearly influenced by C++ don't support multiple
>> inheritance.
>>
>> Just think about one class in the inheritance graph reintroducing a
>> virtual method with different parameters. What will the final class do then?
>>
>> Nothing special.  The new virtual method is just a completely different
> method. Nothing to really bother about. Pascal supports overloading with no
> problems.
>
> Actually what you get from the schema is a single inheritance chain. The
> extension classes would be automatically inserted:
>
> TBase = class(TObject);
> TBase_TAddressExtension = class(TBase);
> TBase_TAddressExtension_TTagsExtension = class(TBase_TAddressExtension);
> TCustomer = class(TBase_TAddressExtension_TTagsExtension);
>
>
> Ondrej
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20170825/02f75994/attachment.html>


More information about the fpc-devel mailing list