Re: Ensuring a method exists



Javier wrote:
Pascal Costanza ha escrito:

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.

Thanks Pascal. Let see if I understand it, I'll give up you an example:

For example you develop a sound application, like Cubase. Cubase uses
VST, which is an especification of abstract classes in C++. Basically,
the devolper enforces you to write a series of methods to ensure that
your plugin will work correctly in the entire system. A similar issue
happens with Java Sound.
What I don't understand from your answer is that interfaces (and
abstract classes) are something that only strongly typed languages
need. I understand that an interface is a void framework of methods
primaly, independetly of the data type of their methods or fields. How
would a CLOS programmer would enforce other users to develop plugins
for their application without an abstract class or interface? (just
asking).

The equivalent of defining interfaces, making them public and asking client software to implement them is to define generic functions, making them public and asking client software to implement them. So, for example, you can define a generic function like this:

(defgeneric add (collection object))
(defgeneric rem (collection object))

You can even define default behavior alongside:

(defgeneric add (collection object)
(:method ((collection list) object)
(cons object collection)))

(defgeneric rem (collection object)
(:method ((collection list) object)
(remove object collection)))

There are some examples in the HyperSpec and in the CLOS MOP specification. For example, print-object, initialize-instance, slot-unbound, slot-missing, and so on, are generic functions that are primarily there for users to define methods on, not for calling them.

What you don't have in CLOS is that you can force client software to explicitly implement methods. It's left up to the responsibility of the programmer to define the right methods, or to leave them out when they are actually not necessary.

It's important to note that static typing doesn't really help you a lot, either. One of the pro-static-typing arguments is that it require programmers to at least think about their design and provide empty methods in case they are not really needed, making that design decision an explicit one. But for example in Java, such a method can still throw an OperationNotSupportedException, divide by zero, or do other silly things. "Modern" development environments like Eclipse even fill in such methods automatically for you - go figure.

So to summarize, a CLOS programmer mainly uses documentation to advertise what a client program has to do to fulfill the needs of a framework.


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: multiple inheritance
    ... slice" of functionality, and use MI to get at it from a class that has this ... to think much more about the design at this level than any most programmers ... I'm a MI AND Interface fan. ... Point 1: Aggregation ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Great SWT Program
    ... orthogonal to whether or not a program has a decent user interface. ... A few also knew the arrow keys existed. ... "useful functionality required to qualify the application as an IDE". ... Or maybe you simply use "real text editor" as a synonym for IDE; ...
    (comp.lang.java.programmer)
  • Re: software design question
    ... Design your interface, and write your program around your interface. ... When functionality A gets created, before component B, likely ... It also doesn't scale very well, though Python ... having a single module, ...
    (comp.lang.python)
  • Re: Web Service Issue
    ... >>You can then do the underlying coding and test the functionality. ... As Michael points out, the goal is to create your services in such a way ... maintain web services by over-simplifying the service interface itself. ... your web service interface as being a conduit to your helper classes. ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: am i using the tag property the right way? please take a look ...
    ... objects which would have all the functionality of the treeview control, ... all treeview properties etc... ... The tag property, while very useful, is of type object. ... interface and polymorphism could someone explain this please, ...
    (microsoft.public.dotnet.languages.csharp)