Version 10 (modified by boyan, 16 years ago) (diff) |
---|
Analysis
Overview
This task is about refactoring the logic operations in the application. The problems related to that include (but are not limited to):
- There are operations that do not use R3 logic.
- There is code duplication (especially in the menu items and bound controls in HUDs).
- There is no convention on naming the events and handlers.
- There is no convention on placing (and grouping) the logic classes.
After this iteration there should be a convention for placing, grouping and naming events and handlers. All existing R3 logics should follow that convention. A lot of the code smells should be eliminated. All old logics will be replaced by new ones. This task is with a bigger scope and might not be finished in one week.
Task requirements
- Create a convention for naming, placing and grouping EventIds, OperationDefs and entries in OperationDefs, apply it and start following it.
- Describe the convention in the UNPLANNED_LOGIC_REFACTORING_R0 section of this page.
- Identify and remove duplicate code.
- Refactor old logic classes to use LogicR3.
- Use LogicR3 handling instead of direct method invocation.
- All buttons, menu items and bound controls should fire an event.
- Use AutoActions when you want to change the model. They should perform a single ModelChange and have a good description.
Task result
- Convention for Logics, described in the design section of this page.
- Source code
Implementation idea
- It seems sensible that all nested ids for events should be named EventIds. Since they are accessed by the wrapper class, it is clear what event they are for. E.g. MenuItem.EventIds.CLICKED.
- OperationDef members that handle an event might be named starting with ON_ (e.g. ON_SET_SCREEN_MODE).
- In the MenuItem there is code duplication on the clicked method. It should become final and fire a CLICKED event.
Related
UNPLANNED_MAIN_WINDOW_REFACTORING_R0
GROUP_BOOK_MODEL_REDESIGN_R0
How to demo
- Show the convention to everyone.
- Show the code and demonstrate that there are no old logics left.
- Run the available tests.
Design
- For the align buttons:
- Create two abstract methods in AlignElementsButton:
- float calculateAlignValue(List<ElementView> selected) - for a given list of element views calculates some align value, for example, the Y-axis of the top-most element.
- ImmPoint calculateNewLocation(ImmRect bounds, float alignValue) - calculates a new location for a single element, given the old bounds and the align value, returned from the above method.
- Replace the clicked method in all align buttons with the above methods.
- Create AlignElementsLogic with a single handler - ON_ALIGN, which listens for CLICKED from AlignElementsButton.
- Calculates the align value
- Creates an immutable list of new locations
- Creates an immutable list of references to elements. Only elements of type MemberElement are collected.
- Creates a new AutoAction that iterates over all references and changes MemberElement.KEY_LOCATION with the newly calculated location.
- Create two abstract methods in AlignElementsButton:
Implementation
Changesets:
- Part 1 (mitex) - renaming, organizing and other basic stuff: [5365], [5366], [5371], [5400], [5403], [5428], [5450], [5451], [5464], [5485]
- Part 2 (jani) - bound controls: [5628], [5641]
- Part 3 (boyan) - app menu items: [5644], EventIds: [5647],[5648]
Testing
(Place the testing results here.)
Comments
(Write comments for this or later revisions here.)