Originally there was the DAL object which my BO’s called for info and then passed to UI. Then I started noticing reduced code in UI and there were Controller classes. What’s the decent recomendation.
I currently structure mine
Public Class OrderDAL Private _id Integer Private _order as Order Public Function GetOrder(id as Integer) as Order ...return Order End Function End Class
then I have controller classes (recently implemented this style)
Public Class OrderController Private Shared _orderDAL as new OrderDAL Public Shared Function GetOrder(id) As Order Return _orderDAL.GetOrder(id) End Function End Class
Then in my application
My app Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click msgbox(OrderController.GetOrder(12345).Customer.Name) End Sub End app
I originally found that with the Shared Class I didn’t have to keep creating a new instance of the DAL whenever I need to fetch data
Dim _orderDAL as New OrderDal _orderDAL.GetOrder(1234) .....
What’s your take?
Thanks
I’ve used your solution in the past, and the only problem I faced is that ‘Shared’ or ‘static’ methods don’t support inheritance. When your application grows, you might very well need to support different types of ‘OrderControllers’.
The estabilished way of supporting different OrderControllers would be, in theory, to create a factory:
The problem here is: what type is returned by ‘ConfiguredOrderController()’? Because it must have the static ‘GetOrder(int id)’ method — and static methods are not supported by inheritance or interfaces. The way around this is not to use static methods in the OrderController class.
and
Hence, you will probably be better off by using non-static methods for the controller.