I have a studentadministration application. Now I have to implement a new part of this application that gives advise (in the style of a text) depending on the grades of the student. So we have 1 “algorithm” and 4(for the moment) different texts(variations) as output).
What is the best pattern in this case?
I personally think about using the bridge pattern so that I can put the algorithm in the abstraction class and put the different texts as concrete implementors.
I think you’re over engineering this.
This is a pretty simple search algorithm problem. Your domain consists of Students (who want advice), Pieces of Advice (who contain knowledge), and a Provider of some kind, which will contain a search algorithm to help the student find advice.
Using the following, I can simply change the search algorithm at any time to suit my needs. I can either create an entirely new search, or modify the one I already have. In addition, I could create a search that works off of a database instead of a list of advice. I can add new criteria by updating my StudentAdvice model and searching for that advice within the provider (these are two distinct changes, so it does not violate the Open/Closed principle).
At it’s core, this could be used as a strategy pattern. However, I started with the domain, and the pattern emerged itself. Picking patterns first codes you into corners.
Learning design patterns gives us a bunch of tools to use. Learning SOLID design principles allows us to realize when those tools should be used. The following site has some great resources related to OOD.
http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod