Inheritance design problem

Hi,

The objective is : There are 2 users of a system, one normal and other privileged. Normal users can use some parts of the system(say,can invoke methods 1-4) and privileged users can use all of the normal users methods(can invoke methods 1-4) and also some other important methods( say,can invoke methods 5-10) also.

To do this, I made 2 interfaces and 2 classes. Following is the details:

interfcae Normal {

public void method1();

public void method2();

public void method3();

public void method4();

}

interface Privileged extends Normal {

public void method5();

public void method6();

public void method7();

public void method8();

public void method9();

public void method10();

}

class NormalImpl implements Normal{

// implements all Normal

}

class PrivilegedImpl extends NormalImpl implements Privileged{

// implements only Privileged

}

Please tell if this hierarchy is correct and posesses good Object design for both the Normal users and Privileged users for now and future.

Thanks in advance

Rajesh

[1176 byte] By [fun_rajesha] at [2007-9-28 5:20:16]
# 1

This design is very inflexible.

Sooner or later someone will get the idea:'mmh, I think we should allow normal users to use method5' you will end up changing the whole system.

I'd use your model only if your API is to be published and your users are actually developers, some of which are allowed to write code against the normal API and some against the privileged API.

A real simple aproach to your situation could be to have a

boolean property for each user 'isPrivileged' and every method takes the user as an aditional argument. Inside the method the 'isPrivileged' property gets checked, before the actual action is performed.

This is very simple aproach .. if you want to see a really powerfull (and complex) aproach have a look at JAAS. And of course there are many ways in between.

regards

Spieler

spielera at 2007-7-9 16:31:10 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
Thank you, so much Spieler..
fun_rajesha at 2007-7-9 16:31:10 > top of Java-index,Other Topics,Patterns & OO Design...