The methodful roles contains the actual algorithm, but what should the Contexts executing method do but execute one of those methods?

public class SomeContext
{
    // ... Constructor omitted ...

    public void Execute()
    {
        // Is this all?
        someRole.DoStuff(this.anotherRole, this.otherData);
    }
}

It seems very simple, so I'm thinking that the Context should be responsible of for example database lookups. Wouldn't that simplify the methodful roles?

有帮助吗?

解决方案

The main responsibility of a context is to bind roles to objects. Sometimes one or more of the "execute" methods will be complex but often they are not. They are there to capture the interaction between objects

The binding of role to objects is atomic. It happens at one location in the context and for all roles at the same time.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top