A good design does not end with following some simple (or complex) design patterns.
For small projects these things won't matter much but keep in mind that small programs become big fearly easily.
To measure a good design versus a bad design I introduce the concept of complexity.
I measure the complexity of a method and a class by the number of concepts a programmer needs to keep in his mind to understand the system.
If you have more than that, your design will not be comprehensible to anybody but experts.
The root cause is a overly flexible possibility to use whatever class you feel necessary.
If every class can just use any other class you'll find a cobweb graph of class usages. To be able to understand a complete object you must understand all concepts.
As a solution I would propose to use facades (or just composition classes) that will hide the additional classes.
If a facade covers off 5 very specific classes then users, that have nothing to do with hoverboards, will not need to know about them in the much more fascinating accounting section of your program.
Composition classes are classes that use classes in the underlying namespace only. So a composition class would use a namespace underneath it to contain all used concepts and classes.
An example:
An ImageProcessor can do all kinds of things to an image.
It can scale them, crop them but also apply a fourier transform on them.
The concepts of scaling needs to be know to be able use the image processor.
If a user interface shows some sort of icons then the user interface shouldn't know about scaling.
It should know about icons. Failure to do so, will create a complex UI that knows about scaling, cropping. We could go as far as to introduce the concept of Fourier transformations in them.
This has some very bad properties to it.
- The UI developer must know about Fourier transforms.
- More concepts makes it all more complex.
- A Fourier transform isn't a UI concept.
Now we work towards creating an algoritm to sort concepts.
First create the domain of the user. Concepts the user should know about.
Concepts that a user doesn't know should get grouped into facade groups and be hidden properly.
15-07-2013, 13:36
Geschreven door denshade 
|