Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top