One of the important aspects of the framework is that it should be highly re-usable. In order to make it re-usable, I’m building it with many small, independent (for the most part) projects. Those small projects will eventually be used to make the more complex projects.
Think of this like cooking. Let’s say that our framework provides potatoes to chefs. Without the framework, each chef needs to get their potatotoes, peel them, slice them up into the shape needed for the recipe, and cook them. If we build something that provides us with peeled potatoes, that saves time for 95% of our recipes. However, if we build something only provides peeled and diced potatoes, that’s not going to help the chef who needs sliced potatoes. If our “cooking framework” only provided us with peeled, diced, roasted potatoes, it would be a great time-saver for 5% of the recipes, but useless for the remaining 95% of them. So, I’m starting out the framework to do the simplest, most common tasks.
In the applications at work, one of the most common tasks is to get a list of jobs from the database. I expect that most programs have their own code to access the database and get this list of jobs. With all those different versions, we end up with several problems.
- - The code for each versions may not be optimized (the query being used, handling of disposable objects, caching, etc.)
- - If we ever need to change the database (or it’s structure), we need modify each program.
- - If we want to improve performance with caching, we end up with one cache per program (not as efficient as a common cache).
- - Each programmer had to spend time writing, testing, and debugging their version of the function.
So, this will be the first thing I’ll add to the framework.
I created two projects: ABCD.BusinessObjects and ABCD.Persistence (”ABCD” will be the fake acronym I use for our real division).
The ABCD.BusinessObjects project will be used in almost every project. This contains classes like the Job object. I’m building these classes using the Data Mapper design pattern. I don’t want to use the Active Record design pattern, where the record contains methods to create, read, update, and delete that object from the database. All the database access code is going into the ABCD.Persistence project. My feeling is that the Active Record pattern produces objects that don’t pass the “Single Responsibility” aspect of the SOLID principles. These classes are currently fairly simple, containing mostly get/sets for the properies.
All the business objects inherit from a BaseBusinessObject class. The only thing in that class is a getter for a virtual boolean property named “IsValid”. It currently returns “true” in the base class. By overriding this method in the derived classes, we can have all the validation rules stored along with the class. Even though the base class doesn’t do anything yet, I put it in place to provide me with a point of flexibility in the code. If we need to add in something that applies to all classes later on, we already have a place to put it. If we don’t, even though this class violates the YAGNI principle, it isn’t a burden on us for performance or developer understanding.
The only thing in this project (other than more business objects) is a class to hold enums used by the business objects. It’s a public static class named ABCDEnums. I’m a fan of using enums for the datatypes of properties. I’ve run into too many situations where a boolean property suddenly needs to store a third value. I believe that FxCop (Microsoft’s code quality tool) even mentions that you should have an “Unknown” or other default value available with each enum. The reason I’ve added this enums class is because it makes the enums very visible through Intellisense. If I can’t remember the exact enum name, all I have to do is type “ABCDEnums.” and they will all appear. That’s also the reason why I’m naming all the namespaces with ABCD.whatever. When I’m adding in my “using” statements at the top of the class, I quickly get to the point where Intellisense starts showing the available namespaces. That’s much easier than trying to remember the exact spelling and upper-casing of some long namespace like “BusinessObjectsForEAISystem”. Although, a tool like ReSharper would be even better (IIRC how it worked during the 30-day trial of it).
My next post will be on the ABCD.Persistence project. I’ve been going back and forth on a couple of ways of building it, and I expect I’ll have that finalized soon.