Re: initializing classes

[email protected]
Newsgroups gmane.comp.audio.supercollider.user
Message-ID <CAFniQ7WV=dA-ckKXBs6uqby_cr1W=Ja=19yBEoAnRSEbM62Zag@mail.gmail.com>
On Tue, Mar 23, 2021 at 11:55 PM <[email protected]> wrote:
> Often it is better and more maintable to use object
> composition ("has-a") instead of inheritance ("is-a")

Fully agreed -- SC does "is-a" way too much, leading users to believe
that "is-a" is the best way (or even the only way). (For instance, I
haven't seen that question in a while, but it does come up from time
to time: "How to subclass a GUI view?" The best answer is usually:
Don't subclass, use SCViewHolder instead.)

That's not to say that subclassing is always a bad idea -- I'm just
re-emphasizing that, when we want to extend the behavior of an
existing class, often we reach first for a subclass, but just as
often, it's probably better to reach first for an Adapter or other
form of object composition.

> Finally, I would like to point out that you don't have to use sclang's
> class system (= classic inheritance), you can also build your object
> system with Events (= prototypical inheritance). Check out the
> documentation of IdentityDictionary - especially the "parent" and
> "proto" properties - for more information on this.

Or the ddwPrototype quark, which makes ~environmentVars local to the
prototype object, so, a bit more transparently object-like then Event
prototypes. (Over ten thousand lines of Proto-based code in the .scd
files here, if you want to see what that looks like --
https://github.com/jamshark70/ddwChucklib-livecode/ .)

hjh

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.