Refractoring a project
Posted: Sat Aug 16, 2008 9:52 am
Hi there.
I have decided deeply refractore (rewrite) my project. I have been working on it for a year or so, it is functional and reasonably stable. Next I plan adding a lot of new functionality. The project already contains dozens of classes, is relatively complex and will become much bigger after adding the new functionality. I am afraid of getting lost if I just add the new functions, without rewriting and standartizing the code.
Below is the list of tasks I have decided to do. Please note that I am using the terms models, views, controllers without intending to fully apply the MVC architecture, bussiness functionality will reside in controllers, while models will be reduced to fetching data from database. Thus the terminology models, controllers may not be correct.
I am limited by the existing code, thus the points below contain tasks that are already partly done or seem feasible.
I would greatly appreciate your comments and suggestions.
1. Object will not use global data directly but only through constructor
2. All objects will be classified as either models, views, controlers or helpers
3. Every base class will contain comments exactly specifying its responsibility
4. Classes with wide responsibilities will be divided.
5. Classes will be renamed according to their main responsibility
6. Autoload
7. Design patterns Singleton, Factory,Strategy, Iterator will be used at all suitable places.
8. Controlers will
- accept all users data
- contact models for getting data from database
- contain bussiness logic (or use helpers for this purpose) apply this logic on database data
- pass data to viewers for rendering
Models will
- create and execute database queries upon request
- will not modify the data they get, only pass them to controllers or store in database
Viewers
- will not apply any bussiness logic on the data, just formatting
9. Write complete tests for every class.
I have decided deeply refractore (rewrite) my project. I have been working on it for a year or so, it is functional and reasonably stable. Next I plan adding a lot of new functionality. The project already contains dozens of classes, is relatively complex and will become much bigger after adding the new functionality. I am afraid of getting lost if I just add the new functions, without rewriting and standartizing the code.
Below is the list of tasks I have decided to do. Please note that I am using the terms models, views, controllers without intending to fully apply the MVC architecture, bussiness functionality will reside in controllers, while models will be reduced to fetching data from database. Thus the terminology models, controllers may not be correct.
I am limited by the existing code, thus the points below contain tasks that are already partly done or seem feasible.
I would greatly appreciate your comments and suggestions.
1. Object will not use global data directly but only through constructor
2. All objects will be classified as either models, views, controlers or helpers
3. Every base class will contain comments exactly specifying its responsibility
4. Classes with wide responsibilities will be divided.
5. Classes will be renamed according to their main responsibility
6. Autoload
7. Design patterns Singleton, Factory,Strategy, Iterator will be used at all suitable places.
8. Controlers will
- accept all users data
- contact models for getting data from database
- contain bussiness logic (or use helpers for this purpose) apply this logic on database data
- pass data to viewers for rendering
Models will
- create and execute database queries upon request
- will not modify the data they get, only pass them to controllers or store in database
Viewers
- will not apply any bussiness logic on the data, just formatting
9. Write complete tests for every class.