swarm-support
[Top][All Lists]
Advanced

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

Re: protocol


From: Ken Cline
Subject: Re: protocol
Date: Mon, 21 Jun 1999 09:06:16 -0400 (EDT)

On Mon, 21 Jun 1999, frink wrote:

> In obj c, is a "protocol" the proper way to implement
> what in C++ is known as an abstract class?

*IMHO*, yes, but they are not exactly the same.  I usually
think of them as more like a Java "interface" (or actually
the other way around, i.e. the Java "interface" is like
the ObjC "protocol").

An abstract class in C++ can have instance variables and
you can provide an implementation of some (or all) of its
methods, whereas a protocol is stictly an interface. My
understanding is that abstract class are typically used
as the base of a (well designed) class hierarchy and that
the word "abstract" is meant to convey incomplete or
unuseable nature of the class if it could be instantiated.

With protocols, the point is to give a name to a piece of
behavior, typically a small piece.  For example, if a client
object only requires that another object provide one or two
methods (e.g. `getFoo' and `setFoo:') then we could wrap-up
this requirement in a protocol.  The "Foo" protocol doesn't
provide a good foundation for a hierarchy but does allow
the client to create a minimal constraint on what objects
it accepts.

The different uses of abstract classes and protocols (or
interfaces) is probably (one of) the reasons Java provides
both.  Protocols/interfaces are used to build a framework
and abstract classes are used to "fill in" the top levels
of the framework's implementation, providing a foundation
that can be easily extended or modified.  (See Java's
Collection API)

... Sorry about rambling on and probably repeating alot of
stuff you already know. I hope it was somewhat useful.

Ken.

*Disclaimer*
 I've never done C++ outside of school and I am, by no
 means, an expert in OOP.  This was just my opinion and,
 as such, please consume it with a few moles of NaCl.
 =:-)

_________________________________________________________
Ken Cline                             address@hidden
SAIC                                 VOICE (410) 571-0413
Annapolis, MD                          FAX (301) 261-8427



                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]