开发者

Optimize way of putting constraints in calling methods of an existing library

开发者 https://www.devze.com 2023-03-25 18:27 出处:网络
Lets say I have a class library which has these following classes: class A { void A1() {} void A2() {} } class B

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
{
  ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消