Re: Ensuring a method exists



Javier wrote:
Going on with this matter, and because I don't fully understand all the
answers you have done:

How would you implement an interface using CLOS with lots of different
methods? For example:

interface Collection {
void add (Object o);
void remove (Object o);
...
}
Tipically, your are going to implement lot of methods, say for example
10 or more.

The main reason for having an interface is that you are going to
provide classes based on it, and let the door open for the user to
implement new ones. So, if it doesn't make sense to implement them on
CLOS because Lisp resolves this problem in a different way, how is that
way? I mean, how is resolving Lisp this problem? Or, if CLOS doesn't
have this problem, why it doesn't?

In Java, interfaces are only necessary to make the static type system happy. When different classes offer similar functionality and you want to use their instances in the same place, they have to have the same type. So either, they are derived from the same common superclass, one is derived from the other, or they implement the same interface. Interface types are more flexible than class types because the former are not restricted to single inheritance. If Java classes would support multiple inheritance, interfaces would not be necessary, but abstract classes would be sufficient (like in C++).

Since Common Lisp is dynamically typed, you don't have to worry about all these things. When different classes offer functionality and you want to use their instances in the same place, you ... just use them.


Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
.



Relevant Pages

  • Re: Ensuring a method exists
    ... How would you implement an interface using CLOS with lots of different ... void remove; ... CLOS because Lisp resolves this problem in a different way, ...
    (comp.lang.lisp)
  • Re: Ensuring a method exists
    ... How would you implement an interface using CLOS with lots of different ... a protocol. ... the resulting set of generic functions embodies the logical ...
    (comp.lang.lisp)
  • Re: alternative to CLOS
    ... i'm curious -- i'd like to see alternative object system ... i have a problem -- CLOS does not work well in ABCL. ... CLOS is quite bloated so i'm unlikely to fix it myself. ... work with new module as long as implements same module interface. ...
    (comp.lang.lisp)
  • Problem getting events from C# to VJ++
    ... interface IWeatherEvents: IUnknown ... public delegate void WeatherChangedDelegate(int nTemperature); ... // float Temperature ... private float m_fTemperature = 0; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Question about Java updates installed?
    ... public long add(int a, int b) ... either encapsulate the add method in an interface and then ... void test() throws Exception { ... A multicast delegate was also possible. ...
    (comp.lang.java.advocacy)