implementing roles in OOP......

From: Mark Nicholls (Nicholls.Mark_at_mtvne.com)
Date: 03/17/04


Date: 17 Mar 2004 02:28:40 -0800

I am having a problem with my coding style.

I have been doing OOD/A/P for several years and over those years has
evolved to a very interface/delegation/pattern based.

My problem is that basic text book implementation of 'roles' that an
object has to satify is by implementing the interfaces of those roles.

This encourages bloated classes implementing more and more interfaces
to satisfy more and more roles and generally makes the implementation
of that class highly coupled between internal states and role.

There is no context for the role i.e. so if I have an object which is
both a a member of two hierachies in two different contexts there is a
interface clash
e.g. a person is a member of a network of family members and a member
of network of work colleagues so....

class CPerson : IFamilyNode,IEmployeeNode
{
bla bla bla
}

but really I want to use a generic node implementation class in two
different roles here, the fact that I have two different contexts
shouldn't really be a problem.

but I can't go

class CPerson : INode,INode // interfaces clash
{

}

I can ask the object for a reference to an interface to that role (and
it's completely up to the class how it implements that interface i.e.
by itself, by returning a contained object, by creating a new role
implementer.....).

This gives a very different style of programming and a whole host of
questions.

i.e. something like
class CPerson
{
 INode AsFamilyNode()
 {
   hmmm now how shall I implement this role?
 }

 INode AsEmployeeNode()
 {
   hmmm now how shall I implement this role?
 }
}

Is there any standard books/literature that discuss this style of
coding?

There are all sorts of questions about identity, what is a role and
what is a class, should roles be able to have sub roles, should I be
able to add and remove roles, how should I process composite
structures of these roles, how can I create reusable role
implementation and compose them together etc etc etc.....

I've sort of looked at web sites for "Role based modelling" and
similar subjects but they are thin on implementation - sticking to the
relative sterile simplicity of the modelling rather than the dirt and
mess of the real world implementation.



Relevant Pages

  • Re: LSP and Equal()......
    ... > If we have GetX and SetX, ... > there is a member X, ... I am more of a fan of COM world of interfaces than the C++ ... necessary to use sealed types then I am happy to loose them. ...
    (comp.object)
  • Re: OT
    ... Member vars with a public interface are in effect set end ... | you are in effect 'overloading' these normaly 'transparent' equivelants. ... means that there is no association between php and your defined interfaces - ...
    (comp.lang.php)
  • Re: IDispose
    ... > Eine Frage habe ich aber noch, Dispose() ist ja der einzige Member ... also nicht als Member des Interfaces ... Der Sinn liegt darin, einer abgeleiteten Klasse zu ermöglichen, ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: Confuesd about abstract class vs interface
    ... It's a fine point, I know, but that is not strictly true. ... Interfaces do not allow the definition of any member (except maybe ... The only requirement of having an abstract class is that _at ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: implementing roles in OOP......
    ... >> I am having a problem with my coding style. ... >> object has to satify is by implementing the interfaces of those roles. ... > Others have suggested patterns for dealing with this at the class level. ... > entity with different views tailored to the subject matter. ...
    (comp.object)