[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Curl, multiple inheritance, and interfaces (was Re: cheerful static typing)



I thought it might be informative/useful to mention a few features in
SmallScript. These features are available for both SmallScript on its
own native AOS VM Platform, and on its implementation for the .NET
platform.

a) Interface is a subclass of Mixin. Interfaces are subclasses of
Interface.

b) Interfaces can provide concrete structure and behavior. They can also
be instantiated directly to obtain "aspects" of an object. Given an
interface on an object, you can obtain the object itself, or obtain
other interfaces on that same object.

c) The language allows the declaration of virtual fields. Which are
invaluable for declaring mixin/abstract classes with fields. A given
implementor may redeclare the field as concrete. Which in turn enables
the jit to have the opportunity to treat the interface methods as
effectively being macros.

d) Selector namespaces can be used to limit/encapsulate access to
interfaces, and can be used to hide interface changes on a class from
other subsystems.

e) Interfaces can be dynamically added to classes (or individual
objects).

f) Interface instantiation is lazy, meaning that interfaces are
instantiated only when required for accessing a concrete field declared
on the interface itself, or when an instance of the interface is
explicitly requested. As in 
    iface := someObj as: ISomeIFace.

g) Interfaces are automatically COM interfaces and all classes
automatically serve as factories; minor work would enable it to provide
equivalent CORBA functionality. The optional type system in SmallScript
and JIT FFI facilities combine to transparently provide the requisite
marshalling and hi-performance vtable/FFI dispatch machinery. The VM
itself is just a loadable/unloadable in-place component.

h) Interfaces can be used to provide MI.

i) Interfaces can be used as an alternative to class-based inheritance
of behavior (and less aptly, structure/layout).

SmallScript supports dynamic modification of classes and methods,
partitioned by modules and selector namespaces. This can be done without
any source code being available. The purpose being to specifically
address fragility problems of just-in-time 3rd party integration.

Module name: MyProject default-scope: MyProject.

Interface name: MyScopedInterface
{
    Function [
    Initialize
	  "" Dynamically register this interface's
        "" behavior/methods to make them available on
        "" all objects (but since it is module scoped,
        "" no code outside our module will have
        "" awareness/access to or be affected by this 
        "" behavior).
        Object addInterface: self.
    ]
	
    Method [
    someMethodWeWantOnObject
        ...method body here...
    ]
}

A basic example of using interfaces in SmallScript is to provide
thread-safe collection subclasses using ABIA (around/before/inner/after)
wrappers to provide synchronized methods.

    """"""""""""""""""""""""""""""""""""
    ""  Thread Safe Wrapper Interface 
    ""  for IndexedCollection protocol
    """"""""""""""""""""""""""""""""""""
    Interface name: IThreadSafeIndexedCollection
    {
    Method [<$around;$synchronous> size 
        ^CallNextMethod()].
    Method [<$around;$synchronous> keys 
        ^CallNextMethod()].
    Method [<$around;$synchronous> values 
        ^CallNextMethod()].
    Method [<$around;$synchronous> keysAndValuesDo: valuable 
        ^CallNextMethod()].
    Method [<$around;$synchronous> addAll: valueCollection 
        ^CallNextMethod()].
    Method [<$around;$synchronous> shrink 
        ^CallNextMethod()].
    }

    """"""""""""""""""""""""""""""""""""
    ""  Thread Safe Wrapper Interface 
    ""  for Map protocol
    """"""""""""""""""""""""""""""""""""
    Interface name: IThreadSafeMap 
              extends: IThreadSafeIndexedCollection
    {
    Method [<$around;$synchronous> at: aKey 
        ^CallNextMethod()].
    Method [<$around;$synchronous> at: aKey put: aValue 
        ^CallNextMethod()].
    Method [<$around;$synchronous> keysAndValuesDo: valuable 
        ^CallNextMethod()].
    Method [<$around;$synchronous> includesKey: aKey 
        ^CallNextMethod()].
    Method [<$around;$synchronous> keyAtValue: aKey 
        ^CallNextMethod()].
    Method [<$around;$synchronous> 
    at: aKey ifPresent: presentHandler ifAbsent: absentHandler 
        ^CallNextMethod()].
    Method [<$around;$synchronous> 
    at: aKey put: anObject ifPresent: presentHandler ifAbsent:
absentHandler 
        ^CallNextMethod()].
    Method [<$around;$synchronous> removeKey: anEntry ifNone:
defaultValue 
        ^CallNextMethod()].
    Method [<$around;$synchronous> removeAll 
        ^CallNextMethod()].
    Method [<$around;$synchronous> empty 
        ^CallNextMethod()].
    }

Allowing us to then declare classes such as:

    """"""""""""""""""""""""""""""""""""
    ""  Declaration Thread Safe Classes 
    """"""""""""""""""""""""""""""""""""
    Class name: SafeDictionary 
          extends: Dictionary 
          implements: IThreadSafeMap.
          
    Class name: SafeIdentityDictionary 
          extends: IdentityDictionary
          implements: IThreadSafeMap.
    

-- Dave S. [SmallScript LLC]

SmallScript for the AOS & .NET Platforms
David.Simmons@SmallScript.com | http://www.smallscript.org


> -----Original Message-----
> From: owner-ll1-discuss@ai.mit.edu
[mailto:owner-ll1-discuss@ai.mit.edu]
> On Behalf Of Dan Weinreb
> Sent: Friday, January 11, 2002 2:14 PM
> To: cbarber@curl.com
> Cc: anton@appsolutions.com; ll1-discuss@ai.mit.edu
> Subject: Re: Curl, multiple inheritance, and interfaces (was Re:
cheerful
> static typing)
> 
>    Date: Fri, 11 Jan 2002 16:30:47 -0500
>    From: "Christopher Barber" <cbarber@curl.com>
> 
>    All this is true, but think of the case in which you do not have
the
> ability
>    to add an "implements" clause to a class because it lives in a 3rd
> party
>    library which you not allowed to change.
> 
> Well, I'm not sure it's "right" to pick up a class from a 3rd party
> library, and "retroactively" declare that it implements an interface.
> It seems that its the prerogative of whoever controls the source code
> of the class to decide what interfaces the class should proclaim that
> it implements.
> 
> The alternative is to make your own class, have it proclaim that it
> implements the interface, and then make its implemention draw upon the
> implementation of that class from the 3rd party library, using
> inheritance-of-implementation or delegation or whatever convenient
> means is at hand depending on the language.