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

JLOVE CONF - Clean Architecture? Clean Code? Refactoring? Tests? What does this change in my code?

JLOVE CONF - Clean Architecture? Clean Code? Refactoring? Tests? What does this change in my code?

In this talk we will cover concepts and applications of clean architecture, clean code, when and how to refactor our code and why it is important to write tests, with examples in Java and Spring Boot. I intend to pass on some good development practices that I have been learning and are widely used in the market.

More Decks by Kamila de fatima santos oliveira

Other Decks in Programming

Transcript

  1. Hi Folks, I’m Kamila Santos Backend Developer at Ame Digital

    github.com/kamilahsantos in/kamila-santos-oliveira/ @kamilah_santos kamila_code
  2. Clean Code Clean code is simple and easy to follow,

    with isolated scope, easy to be tested, and well (self) documented
  3. Clean Code “Any fool can write code that a computer

    can understand. Good programmers write code that humans can understand. ” Martin Fowler
  4. Code, methods and classes that have grown too much, accumulate

    over time as the program evolves Bloaters https://refactoring.guru/refactoring/smells/bloaters
  5. A class that contains many lines of code, methods and

    fields. Bloaters - Large Class https://refactoring.guru/refactoring/smells/bloaters
  6. Use string constants as field names and constants for code

    information USER_ADMIN_ROLE  1 Bloaters - Primitive Obsession https://refactoring.guru/refactoring/smells/bloaters
  7. More than four parameters for a method Bloaters - Long

    Parameter List https://refactoring.guru/refactoring/smells/bloaters
  8. Parts of code that contain identical groups of variables (such

    as parameters of externals configs) Bloaters - Data Clumps https://refactoring.guru/refactoring/smells/bloaters
  9. Very complex switch statements or sequence of if statements OO

    Abusers - Switch Statements https://refactoring.guru/refactoring/smells/oo-abusers
  10. Two or more class perform identical functions but have different

    methods names OO Abusers - Alternative Classes with Different Interfaces https://refactoring.guru/refactoring/smells/oo-abusers
  11. If you need to change something in one place of

    your code , you have to make many changes in other places too Change Preventers https://refactoring.guru/refactoring/smells/change-prev enters
  12. something unnecessary and meaningless, the absence of which would make

    the code more efficient, easier to understand and cleaner Dispensables https://refactoring.guru/refactoring/smells/dispensables
  13. Contribute to excessive coupling between classes or show what happens

    if coupling is replaced by excessive delegation Couplers https://refactoring.guru/refactoring/smells/couplers
  14. Refactoring is the process of changing a software system in

    a way that it does not change its external behavior, but has an improved internal structure. Refactoring
  15. when you go through the code and see the possibility

    of it being improved (and you can invest time in it) When to refactor?
  16. This technique make methods calls simplier and easier to use,

    modifying the interfaces for interaction Simplifying Method Calls
  17. In this category we remove code duplication, simplifies methods and

    prepares application for other refactorings. Composing Methods
  18. Teach how safely move features between classes, hide implementation details

    and create new classes. Moving Features between Objects
  19. Move functionally along the class inheritance hierarchy,i.e create new interfaces

    and classes and replacing inheritance with delegation. Dealing with Generalization
  20. Problem: a method with more than one responsibility, which can

    be extracted for a new method Extract Method
  21. Problem: you have a code that can be represented by

    a constant Replace Number with Symbolic Constant
  22. collection of test cases or specs designed to test a

    program for a specific behavior Test Suite
  23. Test suites are usually divided according to the functionality of

    the system or the type of test performed Test Suite
  24. Test Case shows the paths taken by a module, Use

    Case or functionality within the project. Test Case
  25. exposes the TestEngine interface, which defines the execution contract for

    any testing tool on the JUnit platform Junit Platform
  26. Contains new features for building tests using JUnit, and provides

    a TestEngine implementation for running tests written with JUnit Jupiter. Junit Jupiter
  27. it is a useful method for determining the Pass or

    Fail status of a test case. Declaration methods are provided by the org.junit.Assert class that extends the java.lang.Object class Asserts
  28. is a special form of syntactic metadata that can be

    added to the Java source code for better readability and code structure Annotations
  29. Entities "encapsulate Enterprise wide business rules. An entity can be

    an object with methods, or it can be a set of data structures and functions. "  The Clean Architecture
  30. Use Cases "contains application specific business rules. It encapsulates and

    implements all of the use cases of the system. These use cases orchestrate the flow of data to and from the entities, and direct those entities to use their enterprise wide business rules to achieve the goals of the use case."  The Clean Architecture
  31. Interface Adapters "The software in this layer is a set

    of adapters that convert data from the format most convenient for the use cases and entities, to the format most convenient for some external agency such as the Database or the Web." - The Clean Architecture
  32. Conclusion separating these layers is not easy, but separating them

    from the beginning makes the code more testable and easier to maintain.
  33. General conclusion Among the techniques, clean architecture is the most

    difficult to implement and it is worth considering the learning curve
  34. General conclusion And that radically changes your code :D facilitating

    the maintenance and addition of new features, in addition to the integration of new team members
  35. Thanks <3 Other social networks, examples and slides in qrcode

    Linkedin https://www.linkedin.com/i n/kamila-santos-oliveira/ Twitter @kamilah_santos