I have a base class with a method called Update
:
Start Update
Code block 1 (An If statement)
Code block 2 (Setting a variable based on the If result)
Code block 3 (A switch which is setting something)
End Update
The order in which the code is executed is important so they can't be shifted around.
I also have a derived class which needs a little bit more code. This code however has to be in between Code Block 1 and 2. So when I would rewrite the entire thing it would be something like this:
Start Update
Code block 1 (An If statement)
Code block 4 (An extra calculation based on the If result)
Code block 2 (Setting a variable based on the If result)
Code block 3 (A switch which is setting something)
End Update
I'm looking for ways how to reuse Code Block 1 through 3 and also put Code Block 4 in there.
The best thing I came up with is having a method called Extra
in my base class and have the Update
method look like this:
Start Update
Code block 1 (An If statement)
Call Extra
Code block 2 (Setting a variable based on the If result)
Code block 3 (A switch which is setting something)
End Update
In the base class the Extra
method would be empty since it has no use here.
The derived class would also have the Extra
method but in that method the following would be called:
Start Extra
Code block 4 (An extra calculation based on the If result)
End Extra