2

Just wondering if there is a good way to do this? Currently i'm performing the method calls as if they were happening prior to the conditional block, then comparing what would be the result in "[isDoable == true]" with isDoable being the result of the long chained method call. An example of the method call contained within the if would look something like this.

if(object.getObjectType().getPossibleAction().isDoable(action))...

I realise this is a bit abstract but any help would be greatly appreciated.

2 Answers 2

4

If that's a good idea or not depends on the detail level you want to show in your your diagram and what the reader expects. Also whether you do MDD or not.

Most UML Tools like Magic Draw or Enterprise Architect allow you to define an abstract (displayed) condition and to enter the actual condition in form of code snippets or pseudo code in some usual not visible properties.

I prefer the abstract style like [isDoable == true]. For me it's easier to read. If I need more details I have to look somewhere else (like the code snippet property)

Btw. You may should think about if it would not be a good idea to ask the object directly whether an action is doable rather than exposing the internal structure of objects via call chain. For example object.isDoable(action)

See Law of Demeter

See also IBM's UML Basics: Sequence Diagram

Alternatives

0
1

I'd suggest putting IsDoable() in the interface or in the object, and then providing the action for the check as the parameter. If action is an instance of an Action class, it should be easy to use an overloaded IsDoable(Action myAction) that includes a call to getPossibleAction(). So, the line would become: if(object.isDoable(action))

Or, you could change it so the action doesn't need to be declared ahead of time: if(object.isDoable(object.getObjectType().getPossibleAction())

If you sub-class "object" properly (so you can use the value from .GetObjectType(), and let's call this childObject) and the language allows it, you should be able to do if(childObject.isDoable(childObject.getPossibleAction())

I should note that, if you are creating the action before checking if it is doable, you might want to rethink that. It's usually better to determine which actions are doable, and then create them. But, there are also many scenarios where the only way to determine do-ability is to see what the result would be, or to compare the action to an object that contains the rule set (which is useful when there are multiple rulesets that can be used - like the different variations that casinos have for a single card game). So your order of the operations may be perfectly valid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.