In our daily work, we always write the same code and do it again and again, but how can we create the reusable components for our project and make our code more clearly?
In this article we just explain it at the concept side, so please refer the below 3 points that I have concluded;
1. Think more before you write the logic
Before we write the logic code after we understand the requirement, we must think more about the requirement firstly. make sure that the part requirement clearly. then put the part requirement into the whole architecture, and consider that what will affect the whole architecture based on the CR (change requirement) or the NR (new request ). if the CR or NR has relationship with the original logic, we must be carefull to handle it. but if without relationship, we must design the logic high cohesion and low coupling. after you know the detail of them, then try to design it and write the logic.
2. Conclude the common or the similar logic
It will have most common and similar logic in one architecture, so in the phase of design, we need to find out of them. it's the best feature in OO concept. for example, the date format handler and some other utilize fucntions, we can conclude them then try to create the reusable components. in my first project after I joined the work, we need to handle the JSON and XML arrays without the key, just the value send to us from the 3th part company, they didn't provide us the solution. we send much email to the other team and company to search the common method to handle the response. but all of them us the java array to handle the response in each function. finally, I think that all the work we do are same, just mapping the field by using the index number of the array. so I find that it's just the mapping feature, and suddenly I think that the JPA (Java Persistence Annotation) is the standard for the POJO fields mapping with the data table in database. so I use this case to design my framework like JPA to handle the array response. finally, we use the common util and the annotation, other team member shouldn't care more about the convert, they just care more abou the logic for our project.
3. Create the reusable components at the right layer
High cohesion, and low coupling is the OO design rules. and we need to put it at the right layer, then we can gain the most best from our design. I concluded 3 ways to put the components at the right layer.
A. If your components will be used in each layer, just create a single components, then you can use in each layer.
B. If your components will be used in the superior layer, and the not in the each layer. Create it as a single or create it with the superior layer.
C. If your components will be used in the same layer only, just create it at this layer and separate with logic code.
I think the 3 rules shoshould be like the Maven POM denpendency.
If you create the components correct with right logic, feature and layer, I think that it can make your code profit.
* If you have any doubt, please let me know and we can discuss more about this item.
This article is from the "SG-YYZ" blog, please be sure to keep this source http://sgyyz.blog.51cto.com/5069360/1297002