开发者

Using ICommand interface

开发者 https://www.devze.com 2023-03-08 09:31 出处:网络
I have a class that implements specific interface (IOrganicEnvironment<T, K>) public class Colorizator : IOrganicEnvironment<Cell<YUV>, YUV>, ICommand

I have a class that implements specific interface (IOrganicEnvironment<T, K>)

public class Colorizator : IOrganicEnvironment<Cell<YUV>, YUV>, ICommand
{
    // ..
}

And also it implements ICommand iterface

public interface ICommand
{
    void Execute();
}

IOrganicEnvironment<T, K> interface provides a bunch of methods and properties I'm mostly going to use inside ICommand Execute() method.

But I don't need any client code to invoke that methods and properties from开发者_运维知识库 Colorizator instance.

What can/should I do? If I implement the interface explicitly and make it internal will this help?


I think using composition would be better idea.

public class Colorizator : IOrganicEnvironment<Cell<YUV>, YUV>>
{
   // normal code here
}

public class ColorizatorCommand : ICommand
{
    private Colorizator _colorizator;

    public ColorizatorCommand(Colorizator colorizator)
    {
        _colorizator = colorizator;
    }

    public void Execute()
    {
        //use _colorizator here;
    }
}
0

精彩评论

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

关注公众号