Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to diagramatically represent overridden methods

Consider the following java classes:

public class GenericActionService {

    public void runAction(int actionNo) {

        .... (some stuff)

        runActionCode(actionNo);

        .... (some more stuff)
    }

    protected void runActionCode(int actionNo) {
        switch (actionNo) {
            case 100:
                doSomeGenericAction();
                break;
            ....

            default:
                throw new IllegalArgumentException("Invalid Action!");
        }
    }
}

And inherited sub-class:

public class SpecificActionService extends GenericActionService {

    protected void runActionCode(int actionNo) {
        switch (actionNo) {
            case 1000:
               doSomeSpecificAction();
               break;
            ....

            default:
                super.runActionCode(actionNo);
                break;
        }
    }
}

Now I'm not concerned about whether this is particularly good design or not, and these classes are highly fictional.

What I would like to know is, how do you represent this design with some sort of diagram? Can this be represented using a UML Sequence diagram? If not, what type of diagram should be used?

In particular, I'd like to diagram the flow/sequence when something calls the runAction() method on an instance of SpecificActionService.

For example, consider the flow of execution when runAction(1000) is called on SpecificActionService. I would want the diagram to show the following:

  • Calls SpecificActionService.runAction(1000)
  • Which runs some code in GenericActionService.runAction()
  • Before it calls SpecificActionService.runActionCode(1000)
  • Which calls GenericActionService.runActionCode(1000)
  • Which performs the action
  • Before returning to SpecificActionService.runActionCode(1000)
  • Which returns to GenericActionService.runAction(1000)
  • Where more code is run before it returns to the original caller

The problem is some people consider this to be "modern spaghetti code", especially managers who don't seem to 'get it' when it comes to this kind of inheritence structure, so I'm wanting to document this flow so they understand.

Extra points to those who draw a pretty picture for me. :-)

like image 349
DuncanKinnear Avatar asked Apr 14 '26 22:04

DuncanKinnear


1 Answers

In particular, I'd like to diagram the flow/sequence

So I would use a sequence diagram. This can show how the Objects work together. It did not show you the inheritance structure and how to write the classes but for this you can also add a Class Diagram later.

And here a fancy simple image how this could look: Sequence Diagram

And the plantuml source code if this is not good enough and you want to experiment with this :).

otherObject->SpecificActionService:runActionCode(1000)
SpecificActionService->SpecificActionService:doSomeSpecificAction()

otherObject->SpecificActionService:runActionCode(100)
SpecificActionService->GenericActionService :runActionCode(100)
GenericActionService->GenericActionService:doSomeGenericAction()
like image 104
mszalbach Avatar answered Apr 17 '26 12:04

mszalbach