Link to home
Start Free TrialLog in
Avatar of purplesoup
purplesoupFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Can anyone help me give a class a helpful name related to a design pattern?

I have a class which makes it easier to run automated tests of order processing.


The class has properties and methods to allow different order settings to be specified, then a method is called to run the test and some objects returned to allow confirmation that the test was successful.

I want to know what pattern this might be so I can give the class a helpful name (I've been reading through the various patterns and I can't really identify a good match).

Examples:

var sut = new Tester().WithMugInCart().WithCreditCardPurchase().WithPurchaseSuccessful();

var result = sut.RunTest();

Assert.IsTrue(result.Order.Successful);
etc

Avatar of Jonathan D.
Jonathan D.
Flag of Israel image

var sut = new Tester().WithMugInCart().WithCreditCardPurchase().WithPurchaseSuccessful();

As you can see, you're building the process that the automation has to go through by chaining multiple methods to it. This could potentially be the Chain of Responsibility pattern (not to confuse with creation pattern the Builder Pattern). You're creating the "request" (which is the Tester class) and immediately run through a chain of instructions, thus gives you the flexibility to choose which automation test to run at a specific sequence.

Also, it seems like you're inheriting a characteristic from the builder pattern where each method returns the current instance which then allows you to continue and chain them into a specific sequence. 
Avatar of purplesoup

ASKER

Thanks - that's very interesting - I did wonder about the builder pattern but because it wasn't building and returning the object being tested I wasn't sure if it was legitimate - so with the Chain of Responsibility would a helpful suffix be "Handler" and the name something like "OrderProcessingTestHandler" and the method to run the test "Execute"?
so with the Chain of Responsibility would a helpful suffix be "Handler" and the name something like "OrderProcessingTestHandler" and the method to run the test "Execute"?

I'll give you my honest opinion here and tell you, no. Fancy names are just syntactic sugar, you're not forced to follow names exactly as the design pattern describes. Your method names are fine, more than enough. Don't let it worry you. Besides that, if you're worried about the names then you need to consider to refactor your implementation and follow the exact design as in the link I provided. Ending a method name with "TestHandler" wouldn't be right since it's not really a "handler", it's just a method. a handler is suppose to handle a specific event, so your correct approach would be to link multiple handlers in a specific sequence by having a method that accepts the "handler" method to it. Think of it like the builder pattern, you're "building" a set of "events" that occur at a specific sequence which when executed, they execute at the order they've been set.
ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
var sut = new Tester().WithMugInCart().WithCreditCardPurchase().WithPurchaseSuccessful();

This is known as "fluent" design.