GithubHelp home page GithubHelp logo

code-structure's Introduction

Spring Boot Code Structure

Package Structure

Software Design Principles

Cohesion represents the relationship within a module. Coupling represents the relationships between modules.

Good (loose coupling, high cohesion) Bad (high coupling, low cohesion)

Encapsulation

In software systems, encapsulation refers to the bundling of data with the mechanisms or methods that operate on the data. It may also refer to the limiting of direct access to some of that data, such as an object's components.

Package by Layer

  • Promotes Best Practice (❌)
    • Low cohesion
    • High coupling
    • Low modularity
  • Encapsulation (❌)
    • Most classes must be public
  • Modularity (❌)
    • Since each layer is limited to classes related to a particular layer, it is difficult to break code down into a microservice later on.
  • Maintainability (❌)
    • Since classes are scattered across packages, it is difficult to find the class you are looking for.
  • Testability (❌)
    • Since classes are public, they can be accessed by tests in any package. This allows you to write less focused tests.
  • Domain Driven Design (❌)
    • Promotes Database Driven Design

Package by Feature

  • Promotes Best Practices
    • High cohesion
    • Low coupling
    • High modularity
  • Encapsulation (Minimize Scope)
    • Allows some classes to set their access modifier package-private instead of public.
  • Modularity
    • Since each package is limited to classes related to a particular feature, it is easy to break code down into a microservice later on.
  • Maintainability
    • Reduces the need to navigate between packages since all classes needed for a feature are in the same package.
  • Testability
    • Since classes are not public, they can only be accessed by tests in the same package. This allows you to write more focused tests.
  • Domain Driven Design
    • Promotes Domain Driven Design

Package by Feature & Package by Layer

I have seen that some prefer to break down their project by feature but then add a layer in each feature package. I think this is going to be a little bit of extra work and still have the side affects of package by layer.

code-structure's People

Contributors

danvega avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.