Re: Adding abstract class...

From: AndyW (foo__at_bar_no_email.com)
Date: 04/26/04


Date: Tue, 27 Apr 2004 09:03:39 +1200

On 26 Apr 2004 06:17:30 -0700, sunjaygoyal@hotmail.com (Sanjay Goyal)
wrote:

>There are two questions:
>1. What is the difference between abstract and interface class?
>The answer to this is already posted by R. C. Martin.
>

It depends on what camp you are in as to how you approach OO. There
are two main ones. The technical camp based on the approach developed
by Booch (87) where an object has identity, state and action.

The second camp is the purist form where an object is defined as
having identity, state, action and tangibility (it must be a real
world thing).

The technical guys tend to have come into OO from a programming
background and try to fit the concept to the language (in my
observations). Everything is treated as an object depending on its
granularity. The result is that an abstraction and an interface tend
to be used and treated in the same way.

The implementation of an interface in this camp is often treated as an
object in its own right. The same tends to happen with an abstraction.

The purist camp generally approach OO in its real form and just use
any language as a method for implementing the concepts. Only real
world things that exist are treated as objects with services and
mixins being used to handle those entities that dont make the grade.

In this form an abstraction is very rarely used since they are just
concepts of objects rather than tangible things, so its not often we
really have a need for working with them. Perhaps only when we need
to deal with a collection of related but different objects.

Interfaces in the purist camp are used only for defining a subset of
functionality of an object for use in a particular way. At this level
an object is defined as the class (or group of classes if its a
complex object) and all of its associated interfaces.

Think of it as defining the different ways that I can use an object.
For example I might use a pencil for writing or for digging the dirt
out from under my finger nails. Two interfaces for the same object.

You could add all your methods (behaviour) into a single object, but
that makes it complex (and difficult for the human to understand how
to use it). Or you could split the different types of behaviour into
related chunks - this is interfaces.

Abstraction is when I need to deal with a number of related objects in
a generic way. For example I might have a 1B pencil a 2B pencil and a
1H pencil. When I talk to someone about writing, I just need to
refer to a pencil (the abstraction), but if I am showing someone how
to shade a drawing, I will refer to the specific object - the 2B
pencil.

The problem with the technical camp is that they tend to mix the two
together (treating an interface as a kind of abstraction), so you
would often get 'the pencil that I use to dig the dirt out from my
finger nails' and the 'pencil that I am using to shade the drawing
with'. The problem with this is that while the first statement
seems ok, you dont really need to know what type of pencil you are
using to clean your finger nails, it falls down when you try to show
someone how to shade the drawing - knowing what type of pencil you are
using is very important.

On a side note, no-one ever said you had to put methods and attributes
in an abstraction or an interface and in the technical camp the two
would look the same - hence they tend to get mixed up. In the purist
camp the two things have totally different meanings no matter what
they actually consist of.



Relevant Pages

  • Re: Adding abstract class...
    ... What is the difference between abstract and interface class? ... The technical camp based on the approach developed ... The same tends to happen with an abstraction. ... > For example I might use a pencil for writing or for digging the dirt ...
    (comp.object)
  • Re: object system...
    ... for that you need machine language. ... there are many other cases where "abstraction" can be leveraged to the ... never have an interface to access not doing something. ... based on class systems rather than type systems. ...
    (comp.object)
  • Re: object system...
    ... in order to use abstraction as self-target. ... Note that an object is defined by its responsibilities. ... never have an interface to access not doing something. ... The 3GL type systems are a compromise with the hardware computational models. ...
    (comp.object)
  • Re: Modeling Infra Interfaces in UML
    ... It's clear what's going on at that level of abstraction. ... Lollipop to represent the offering of an interface is what I've seen in the ... in stereotypes to represent non-concrete interfaces. ... I would use notation as close as possible to 'singleton' class like ...
    (comp.object)