官术网_书友最值得收藏!

Software design patterns and principles

Your will probably be using object-oriented (OO) or functional programming in your microservices or Lambda code, so let's briefly talk about the patterns linked to them.

In OO programming, there are many best practice patterns or principles you can use when coding, such as GRASP or SOLID. I will not go into too much depth as it would take a whole book, but I would like to highlight some principles that are important for microservices:

  • SOLID: This has five principles. One example is the Single Responsibility Principle (SRP), where you define classes that each have a single responsibility and hence a single reason for change, reducing the size of the services and increasing their stability.
  • Package cohesion: For example, common closure-principle classes that change together belong together. So when a business rule changes, developers only need to change code in a small number of packages.
  • Package coupling: For example, the acyclic dependencies principle, which states that dependency graphs of packages or components should have no cycles.

Let's briefly go into some of the useful design patterns for microservice:

  • Creational patterns: For example, the factory method creates an instance of several derived classes.
  • Structural patterns: For example, the decorator adds additional responsibilities to an object dynamically.
  • Behavioral patterns: For example, the command pattern encapsulates a request as an object, making it easier to extract parameters, queuing, and logging of requests. Basically, you decouple the parameter that creates the command from the one that executes it.
  • Concurrency patterns: For example, the reactor object provides an asynchronous interface to resources that must be handled synchronously.

Depending on you coding experience, you may be familiar with these. If not, it's worth reading about them to improve you code readability, management, and stability, as well as your productivity. Here are some references where you can find out more:

  • SOLID Object-Oriented Design, Sandi Metz (2009)
  • Design Patterns: Elements of Reusable Object-Oriented Software, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides (1995)
  • Head First Design Patterns, Eric T Freeman, Elisabeth Robson, Bert Bates, Kathy Sierra (2004)
  • Agile Software Development, Principles, Patterns, and Practices, Robert C. Martin (2002)
主站蜘蛛池模板: 双辽市| 武清区| 章丘市| 河曲县| 滦平县| 葵青区| 石泉县| 鹤庆县| 九台市| 如皋市| 琼结县| 东阿县| 岢岚县| 屏南县| 呼玛县| 陈巴尔虎旗| 波密县| 紫阳县| 密山市| 五家渠市| 柘荣县| 耒阳市| 青岛市| 安福县| 泰来县| 阿克陶县| 突泉县| 城市| 景德镇市| 石屏县| 土默特左旗| 武威市| 太白县| 蛟河市| 德庆县| 商都县| 南丰县| 大冶市| 乌兰察布市| 九龙县| 河津市|