Lets say I have a class library which has these following classes:
class A
{
void A1() {}
void A2() {}
}
class B
{
void B1() {}
void B2() {}
}
class C
{
void C1() {}
void C2() {}
}
In my client code I开发者_如何学JAVA am doing this:
Class Client
{
A objA = new A();
objA.A1();
// Same for other classes and their methods
}
Now I have a change request which requires me put some constraints (say RightAcess etc.) while calling the library methods. I have more than 30 classes to update. What is the optimized way to achieve this?
Its better to have base class for all your class and implement the same function inside the base class
class BaseClass
{
public object RightAcess()
{
//[Code]
}
}
class A : BaseClass
{
...
}
class B : BaseClass
{
...
}
class C : BaseClass
{
...
}
精彩评论