I am looking for some guidance regarding OOP:
Say for instance i have the following two classes:
public class CallbackModel : SharedModel
{
public CallbackModel() : base()
{
}
public IList<Callback> getData(DateTime start, DateTime end)
{
StringBuilder query = new StringBuilder();
query.Append("SELECT LAST_UPD AS PERIOD, ");
query.Append("COUNT(CASE WHEN STATUS ='Færdig' THEN 1 END) as completed, ");
query.Append("COUNT(CASE WHEN SOLVED_SECONDS /60 /60 <= 2 THEN 1 END) as completed_within_2hours ");
query.Append("FROM KS_DRIFT.NYK_SIEBEL_CALLBACK_AGENT_H_V ");
query.Append("WHERE LAST_UPD BETWEEN '" + start.ToString("yyyy-MM-dd") + "' AND '" + end.ToString("yyyy-MM-dd") + "' ");
query.Append("AND STATUS ='Færdig' ");
query.Append("GROUP BY LAST_UPD ORDER BY LAST_UPD ASC");
var session = sessionFactory.OpenSession();
var result = session.CreateSQLQuery(query.ToString())
.AddEntity(typeof(Callback))
.List<Callback>();
return result;
}
}
And
public class HenvendelserModel : SharedModel
{
public HenvendelserModel() : base()
{
}
public IList<Henvendelse> getData(DateTime start, DateTime end)
{
var query = "SELECT " +
"TIDSPUNKT AS PERIOD, " +
"NVL(QUEUE,' ') AS QUEUE, " +
"NVL(SUM(ANTAL_KALD),0) AS CALLS, " +
"NVL(SUM(ANTAL_BESVARET),0) AS ANSWERED_CALLS, " +
"CASE WHEN NVL(SUM(BESVARET_25_SEK),0) > 0 THEN ROUND(NVL(SUM(BESVARET_25_SEK),0) / NVL(SUM(ANTAL_KALD),0) * 100) ELSE 0 END AS ANSWER_PERCENT_25, " +
"NVL(SUM(INTERN_KALD),0) AS INTERNAL_CALLS " +
"FROM KS_DRIFT.PERO_NKM_KØ_OVERSIGT " +
"WHERE TIDSPUNKT >= '"+start.ToString("yyyy-MM-dd")+"' " +
"AND TIDSPUNKT <= '" + end.ToString("yyyy-MM-dd") + "' "+
"GROUP BY QUEUE, TIDSPUNKT " +
"ORDER BY PERIOD";
var session = sessionFactory.OpenSession();
var result = session.CreateSQLQuery(query)
.AddEntity(typeof(Henvendelse))
.List<Henvendelse>();
return result;
}
}
Now in my program i have several of these type of classes (for the purpose of example lets say about 7 or 8).
Now my view would have to get an instance of each of these Model classes in order to call the method getData()
My question is what is the best way to do this? is it just instantiate each model in the view directly or is it better to use a subclass and have the view ask for each of the models?
i just don't like having a long list of Model
classes in my view. is there a design pattern for this that i am missing?