I've been having some trouble coming up with a design that would alleviate most, if not all, the issues I've been running into, and I'm wondering if it is my base design.
Our company accepts orders. We accept different types of orders based on the product line they belong to, but all orders share some functionality and properties. My goal is to inject any order implementing a specific interface into a OrderRepository class.
In order to fulfill these needs, I created an OrderBase class:
public class OrderBase {
public string order_number {get; set;}
public string order_type {get; set;}
public string order_date {get; set;}
public List<IOrderItem> order_items { get; set; }
public virtual bool Validate();
}
I created an interface that mimics the base class so I can utilize the base class as exactly that... the base functionality for an order.
public interface IOrder {
string order_number {get; set;}
string order_type {get; set;}
string order_date {get; set;}
List<IOrderItem> order_items { get; set; }
bool Validate();
}
One type of order is implemented as such:
public class TXOrder : OrderBase, IOrder {
// Specific to TXOrder only
public bool isOnHold {get; set; }
public override bool Validate() {
// Enter TXOrder-specific validations here.
return base.Validate();
}
}
TXOrder inherits the base class, getting all those properties and methods and the implemented interface is fulfilled by the base class properties and methods. This works well right now with ModelBinders that map to the correct object per the data coming in.
The repository looks like this:
interface IRepository<T, U>
where U : IParameters
{
T SelectSingle(long id);
List<T> Select(U parameters);
T Insert(T entity);
T Update(T entity);
T Delete(T entity);
}
public class OrderRepository: IRepository<IOrder, OrderParameters> {}
If you need the gory details of the OrderRepository, don't hesitate to ask. It accepts any order I throw at it of type IOrder. That's the key point to take away.
Is this a pattern that can continue to work long-term as I add specific functionality for each order type? Is there another pattern I can look at?
Validate
method?