I am having problem designing a module.Can anybody help me
This is basically an agricultural project (web application).I need to design module where some calcuation takes place.
There are differnt crops invovled like maize,tomato,okra etc.Now each of these crops have different traits.
Each trait has a mesurament scale which lies in integer like 200-1000.now let say i have planted the crop and
done measurement noted down the traits.Now i want to do some sort of measurement.Some measurements are simple and some are
Lets take an example of crop maize.I have recored observations for 15 trait.(trait1.. trait15 are just alias the acutal name can be like plt_ht,yld)
trait1 trait2 trait3 trait4 trait5 trait6..... trait15
i have recorded 5 observations for each traits
trait1 trait2 trait3 trait5 trait6..... trait15
01,02,03,04 01,02,03,04 01,02,03,04
User logs into system and selects his crops and enters data for these observation i either have to calculate average of those data entered for each or sum of those.
This is simple but complexity comes when for some of the tratis i have some different formulas. Like lets take an example let say a trait YLD has a formula based on which i have to caluate its value which may also depends on some other traits .This way all differnet crops have different traits.All this i am able to do whenever user selects crop i will check for those specific traits and do calculations if it is not special trait then i eaither avg it or sum it based on db entery but there is lot of hard coding .I want to have some suggestion from you people if u can think of an better way of handling this.
complexity comes when for some of the tratis i have some different formulas.
In such cases the Strategy design pattern is often used.
To understand how it works take sorting as an example. Instead of writing a different sort module for each and every kind of item you want to sort you write one general sort module and then for each specific item you supply a strategy for how exactly this kind of item is to be sorted. In the sort case the strategy simply tells which of two items is the bigger. That's all the sort algorithm needs to know about items to sort them.
In the same way you could separate and encapsulate what's specific about each trait from what's general for all traits. The trait specific strategies are then passed in to otherwise trait independent algorithms/code. In practice this can be done in different ways depending on your coding style and programming language. In C++ 11 a nice way is to use lambdas.
Last edited by nuzzle; December 7th, 2012 at 02:39 AM.
This sort() method will sort any kind of item as long as a proper strategy object implementing the Comparator interface is passed in. In this case the strategy object is called MyIntComparable and determines the relative order between two Integer objects. If you want to sort something else or Integers in some other way you pass in another strategy object.
That shows the principle of the Strategy pattern and how it may be used but you'll have to adapt it to your situation of course. And if it doesn't fit consider other patterns or combinations of patterns. As it happens one of the best introductory book uses Java as model language. It's Head First Design Patterns by E & E Freeman.
Last edited by nuzzle; December 9th, 2012 at 01:00 AM.
There are crops and each crop have traits , traits are actually a mesuremet scale to decide growth of a seed of a particular crop. This module is to for planters to observe growth of seeds sowed of certain crops and take down n no of observation for each trait and upload in csv format.Once they enter data i have to either avg out the values or sum the values or sometimes there are more complex function that i have to apply it may differe for each trait .This is the whole module about.Just to give an idea about how they will enter data
Once they enter data in this format i have to give result something like this.
Here avg colum does not necessaryly mean avg it can be sum or any formula based resutl.Hybrid is the seed for which they record the observation. I have shown avg column only for two tratis it is actually for all the traits.