Class / interface overloading

61 views
Skip to the first unread message

Dietmar Höhmann

unread,
27 Jun 2015, 06:37:3427/06/2015
to ceylon...@googlegroups.com
Hello everyone,

I must admit I didn't think through this to the very end - so it might turn out to be a silly idea: I'd like a mechanism to overload an existing class, thus changing all derived classes. I don't know if this is at all possible. And the effect must be strictly bounded to my own module(s). But it would simplify this scenario much: I'd like to extend the functionality of ceylon.html to reflect all changes to an html page directly into the browsers DOM tree. It should be sufficient to extend the class Element with a DOM adapter. But without class overloading I need to duplicate all derived classes.

Gavin King

unread,
27 Jun 2015, 09:09:5527/06/2015
to ceylon...@googlegroups.com
I'm not quite certain what you mean by "overload" here. I think you
mean something a bit like "open classes" in a dynamic language.

Example?
> --
> You received this message because you are subscribed to the Google Groups
> "ceylon-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ceylon-users...@googlegroups.com.
> To post to this group, send email to ceylon...@googlegroups.com.
> Visit this group at http://groups.google.com/group/ceylon-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ceylon-users/e41bdc99-a59e-4aa1-8861-aca23679be1c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Gavin King
ga...@ceylon-lang.org
http://profiles.google.com/gavin.king
http://ceylon-lang.org
http://hibernate.org
http://seamframework.org

Dietmar Höhmann

unread,
27 Jun 2015, 09:53:1427/06/2015
to ceylon...@googlegroups.com
What I want to achieve is: When my code instantiates let's say H2 from ceylon.html the resulting object should be a:

H2 (from ceylon.html)
Heading (from ceylon.html)
BaseElement (from ceylon.html)
StyledElement (from ceylon.html)
Element (from my.code.html, extends Element from ceylon.html)


So to say I'd like to replace a class within the inheritance chain with an extended version of it. And I need this to be able to execute own code whenever an Element is instantiated.

Gavin King

unread,
28 Jun 2015, 18:01:2928/06/2015
to ceylon...@googlegroups.com
Well, no, Dietmar, there's no way to dynamically mess with inheritance
chains in Ceylon. This is the kind of thing you can do in languages
with dynamic typing, but not usually in languages with static typing.
And it would be rather unnatural to implement something like that for
the JVM.

In some languages with static typing there is the ability to add a
type class to an existing type but I'm not sure if that's the kind of
thing you're looking for. Ceylon doesn't have anything like that
however. I don't know of any statically-typed JVM language which does,
FTR.
> --
> You received this message because you are subscribed to the Google Groups
> "ceylon-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ceylon-users...@googlegroups.com.
> To post to this group, send email to ceylon...@googlegroups.com.
> Visit this group at http://groups.google.com/group/ceylon-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ceylon-users/f9f3f83b-823b-4321-b08c-686cc1400ff0%40googlegroups.com.

Sven Linstaedt

unread,
29 Jun 2015, 09:46:0629/06/2015
to ceylon...@googlegroups.com
That sounds like a classical "use case" for design patterns like the bridge one.

Dietmar Höhmann

unread,
29 Jun 2015, 10:34:1229/06/2015
to ceylon...@googlegroups.com
Yes and no. If the html classes were created that way yes. But they are not, so what I need is to attach my code to a standard class I could not change. But this is not possible (at least not in a standard way), and thus I must copy the entire class hierarchy.

Gavin King

unread,
29 Jun 2015, 11:06:4729/06/2015
to ceylon...@googlegroups.com
Hrm, it's *almost* a problem that you could use a type family for ...
except, type families work when you have like 2 to 5 related classes.
Not so much if you have like 40, I suppose...
> --
> You received this message because you are subscribed to the Google Groups
> "ceylon-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ceylon-users...@googlegroups.com.
> To post to this group, send email to ceylon...@googlegroups.com.
> Visit this group at http://groups.google.com/group/ceylon-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ceylon-users/47eda05b-9123-40b0-991a-47dedabd623f%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages