How to Create an Reusable Components for Your Project
2013-09-14 11:35
441 查看
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 should 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.
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 should 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.
相关文章推荐
- How To Create an ASP.NET Application from Multiple Projects for Team Development
- How to create a maven repository for your github project step by step
- How to create an installer for your Python program
- (转载)XML Tutorial for iOS: How To Choose The Best XML Parser for Your iPhone Project
- How To Choose The Best XML Parser for Your iPhone Project
- how to create 2D visibility/shadow effects for your game
- How to create jar for Android Library Project
- How to create installation patches for VS.NET deployment projects
- How to generate an RSS feed for your web site using ASP.NET
- How to add QuartzCore.framework for your project in xcode?
- What is Favicon.ico and How to Create a Favicon Icon for Your Website?[zz]
- Windows Phone Dev Center - How to create your first app for Windows Phone
- How To Choose The Best XML Parser for Your iPhone Project
- How to create multiple targets for Xcode iPhone Projects
- How To Choose The Best XML Parser for Your iPhone Project
- SAP CRM How to Create your own BOL Object for webclient
- git tip: How to undo an uncommitted change/deletion for a specific file in your working directory
- How to generate an RSS feed for your web site using ASP.NET
- How To Choose The Best XML Parser for Your iPhone Project
- javascript - C++, Qt, QtWebKit: How to create an html rendering window so that your application would get callbacks from JS calls? - Stack Overflow