Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Forgetting Unity

Forgetting Unity

Clean Architecture and How to apply it to a Unity3D Project

Cookingsource

February 11, 2014
Tweet

Other Decks in Programming

Transcript

  1. Abuse of certain patterns on tutorials Most of the things

    are Monobehaviors or scriptable objects Manager classes that do too much Singletons for every system dependency Gameplay mixed with presentation code But people ask on the community for better ways to do it.
  2. Why not MVP, MVC, MVVM, Other …? On apps it’s

    not a discussion point Is there some intrinsic constraint enforced by Unity? Nope Lack of examples of how to decuple your game logic from unity API Fear of producing more complex code for little gain
  3. Can TDD be applied to games? On the unit test

    level for sure if you are well decoupled Also Unity has recently provided a way to do integration testing What for? So that the team don’t fear the refactor Do it well or don’t do it.
  4. The benefits Clear definition of the purpose of the business

    logic Possibility to defer crucial decisions about dependencies Test friendly code Code reuse Easier to maintain Easier Porting
  5. Interactors They implement use cases They are named as verbs

    Can be implemented as a command pattern, but it’s not a requirement They orchestrate the interaction with the application agnostic rules The input and output data must be plain DTOs
  6. Entities Implement the application agnostic business rules They model behaviour

    not plain data Don’t depend on any code out of the entities layer.
  7. Boundaries Provides the required abstractions to decouple the interactors from

    the other layers. The classes that cross the boundary are also part of the of their definition In a static object oriented language they’re defined as interfaces Interactors implement some boundaries Interactiors implementations may depend on other boundaries
  8. Entity Gateways The only other classes that can access the

    entities. They define the entity provider dependencies as interfaces. Their implementations map an entity definition to the models of external layers.
  9. Common Pitfalls and Issues Pushing data out of the boundary

    Pushing data into the boundary Anemic Domain Asychronous Boundaries Model Duplication
  10. Integrating with Unity Create a monobehavior that initializes the presentation

    and the core logic Add it to the script execution order before any other script present there Wire the time dependant call to the presentation and the core ( if any ) Your Unity scripts should now only handle representation logic Provide the views access to their viewmodel so they can represent it