How to think about class design (division) in a business system (1)

It is a theme that I am still exploring, but I will write it down because the policy has been set and the results have been obtained. For those who know it, it's "natural", so skip the article. The content is for young to mid-career. I hope that the discussion will further improve it.

Premise

  1. Java application (C # is fine, if it's an object-oriented language)
  2. For business systems regardless of BtoC or BtoB
  3. Includes Web API etc. In short, Java batch etc. are not covered.
  4. The project team's programming skills are not that high.
  5. Imagine a team that has a large number of SEs (no longer coder) who have no skills even though the cost is full-fledged due to the harmful effects of multiple subcontractors.

Points to consider

  1. I want to have a configuration that flexibly responds to changes in business (change / addition / deletion of requirements).
  2. It will be continuously renovated in the future, but since there is a high possibility that the members will be replaced, readability is important.
  3. I don't want to put in a very difficult theory because I can't expect the skills of project members. (I don't like DDD)

Is it such a place? The point is, "I want to write code that can be easily extended with simple code."

Conclusion

Write a brief conclusion. The class is divided vertically (procedurally) and horizontally (object-oriented) according to the role. It's not a big story, but how to divide Controller / Service / Repository in Spring Boot.

Concept 1: Premise that business is unique and mechanism is common

To put it simply, system development is often about getting the customer done. It's about efficiency and business creation. So, what is important at this time is ** When you look at various systems, what are the common parts and the parts that are not common ** </ font>? That's exactly what the headline says, and the customer's business itself is not the same. However, there is a high probability that the mechanism for achieving this is common.

Business is unique

For example, when considering the system of international remittance business of banks and ordering business of convenience stores, how much are the procedures in common? Isn't it 0? In this way, if the business type is different, the business will be completely different. Also, even in the same international remittance business, it will be different when a bank does it and when a securities company does it. Even among the same banks, UFJ and Sumitomo will be different (if the business is the same, it can be realized at low cost by installing the same system). In other words, basically the business part cannot be reused.

The mechanism is common

Even if the business system is completely different, the mechanism used in it is usually the same. What this means is that if you want to store data, use LDAP or SQL, and if you want to send a telegram, use HTTP or SOAP. In other words, you can see that the part of the mechanism such as storing in the DB or sending the request somewhere is common (or reused). If you focus on an industry, you may be in compliance with the standard. For example, it has been decided to use Swift Telegram for international remittance, so it seems that the mechanism is the same within the scope of international remittance business.

Concept 2: Accept duplicate code due to business

Occasionally, there are extremists who do not allow duplicate code at all and can call code that appears more than once as a method, but if you create a class or method with this idea (although it does not go so far ...) , It becomes impossible to separate according to the role, and a chaotic code is created in terms of both naming and function division. Also, even if it was beautifully divided by Extends etc. at first, there are cases where you want to change only a small part of the inherited class while continuing the repair (in the worst case, at the time of the next repair). ファイル名 Even if such a class is created first and divided beautifully, AbstractClass2 will be created and double inherited for processing that is only partially different in the next modification. It's the beginning of hell. ファイル名 I have seen up to quadruple inheritance.

In the past, it was said that unique codes were beautiful, but in cases where members with low skills are frequently replaced, complicated codes become a baggage. This is because the code cannot be understood or maintained. Then what should we do. Think separately for business and mechanism, implement the business part in each class, and standardize the mechanism part. Even if some duplicate code occurs, the business part is implemented individually. Even if most of them are common, it will be easier to repair. ファイル名 Method1 is implemented in the business class like this. The content of method1 may contain duplicate code, but let's accept the duplicate as a different business. Then, even if there is a requirement that you want to change only one of the tasks that were the same at the beginning, you can correct it by making the minimum changes. Method2 is placed in AbstractClass as a common mechanism.

It's getting a little longer, so let's continue with the next article.

Recommended Posts

How to think about class design (division) in a business system (1)
Mapping to a class with a value object in How to MyBatis
Things to think about when deciding on a new system architecture
How to insert a video in Rails
How to fix system date in JUnit
How to publish a library in jCenter
How to get keycloak credentials in interceptor class
How to display a web page in Java
How to create a class that inherits class information
How to get Class from Element in Java
How to convert a solidity contract to a Java contract class
How to add a classpath in Spring Boot
How to create a theme in Liferay 7 / DXP
How to implement a like feature in Rails
How to make a follow function in Rails
How to automatically generate a constructor in Eclipse
How to check if an instance variable is defined in a Ruby class
How to create a Java environment in just 3 seconds
About class division (Java)
How to implement a like feature in Ajax in Rails
How to get information about associated tables in many-to-many tables
How to create a Spring Boot project in IntelliJ
How to create a data URI (base64) in Java
How to launch another command in a Ruby program
How to display a browser preview in VS Code
How to think when you suddenly understand about generics
[How to insert a video in haml with Rails]
How to write a date comparison search in Rails
How to store Rakuten API data in a table
How to convert A to a and a to A using AND and OR in Java
How to convert a file to a byte array in Java
[Rails 6] How to set a background image in Rails [CSS]
[Rails] How to load JavaScript in a specific view
How to write a core mod in Minecraft Forge 1.15.2
[Ruby/Rails] How to generate a password in a regular expression
How to get the class name / method name running in Java
How to change a string in an array to a number in Ruby
How to create a placeholder part to use in the IN clause
How to store a string from ArrayList to String in Java (Personal)
How to move another class with a button action of another class.
How to select a specified date by code in FSCalendar
How to display a graph in Ruby on Rails (LazyHighChart)
Think about how to divide MVC into M and V
How to simulate uploading a post-object form to OSS in Java
How to create a service builder portlet in Liferay 7 / DXP
How to set up a proxy with authentication in Feign
A story about misunderstanding how to use java scanner (memo)
How to leave a comment
How to use java class
How to insert a video
How to create a method
How to make a jar file with no dependencies in Maven
How to implement a job that uses Java API in JobScheduler
Handle business logic for a set of Entity in Java class
How to create a new Gradle + Java + Jar project in Intellij 2016.03
How to automatically operate a screen created in Java on Windows
How to run a job with docker login in AWS batch
Creating a matrix class in Java Part 2-About matrices (linear algebra)-
How to rename a model with foreign key constraints in Rails
How to store the information entered in textarea in a variable in the method
How to output a list of strings in JSF as comma-separated strings