I started developing a small application and had some questions related to architecture.
I have some basic objects that I am ready to model - Repository and Indicator .
Repository is basically a facade using the Repository Pattern , which is able to retrieve / store arbitrary objects using some database holder (right now it is NHibernate -driven, but I think this is not very important).
Indicator can be called the logical core of my application. It is used to combine abstract values ββand the exact time to reach this value (therefore, it is formed and works with Value - Time pairs).
I am ready to make this Indicator as general as possible, but I think my current solution is a big failure :)
See the following code snippets:
public interface IIndicator<T> { IEnumerable<T> RetrieveValues(DateTime start, DateTime end); }
This is the main attempt to implement the indicator (right now it can be considered as a layout):
public class Indicator<TValue> : // Self-referencing generic parameter. IIndicator<Indicator<TValue>.TimestampProxy> { // Proxy, which is used to add the timestamp to // every indicated value. public class TimestampProxy { public TValue Value; public DateTime Time; public TimestampProxy(DateTime time, TValue value) { Time = time; Value = value; } } private readonly IRepository repository; public Indicator(IRepository repository) { this.repository = repository; } public IEnumerable<TimestampProxy> RetrieveValues(DateTime start, DateTime end) { // Note the custom time stamp comparation in the lambda // expression. Comparation includes the 'start' and 'end' limits. IQueryable<TimestampProxy> queryable = repository.Retrieve<TimestampProxy>( x => x.Time.CompareTo(start) >= 0 && x.Time.CompareTo(end) <= 0); return queryable.ToList(); } }
Now - it may look fine, but I'm absolutely sure that the used TimestampProxy really evil.
It also complicates the comprehension (for example, signing the IEnumerable<TimestampProxy> RetrieveValues(...) method will probably result in the phrase βwtf ?!β from the person who is studying the code).
Unfortunately, I cannot come up with a better solution / global redesign - could you advise me how to do this, or just tell me some ideas about how this function should be implemented?
Thanks.