tags:

views:

62

answers:

1

Take for example:

CreateOrderTicket(ByVal items As List(Of OrderItems)) As String

Where would you put this sort of logic given:

CreateOrder should generate a simple list ( i.e. Item Name - Item Price )
PizzaOrderItem
SaladBarOrderItem
BarOrderItem

Would you recommend: Refactoring common to an abstract class/interface with shared properties a method called CreateOrderTicket

Or,

Creating a common service that exposes a CreateOrderTicket

We obviously would not want three createOrderTicket methods, but adding methods, inheriting, overloading and using generics seem like a high cost just to abstract one behaviour..

Assume for the sake of a simple example that (currently) there is no OrderItem baseclass or interface..

Help!! :)

p.s. Is there a way to overload without forcing all inheriting objects to use the same name?

+1  A: 

Abstract base class sounds like the best option in this situation. Of course it all depends on what kind of shared behaviour these items have. Without knowing more, I'd guess all of these order items have Name and Price for example - and in future you might add more common stuff.

Without a shared base class which contains the Name and Price properties, you'll probably have troubles implementing a CreateOrderTicket method which takes a list containing more than 1 kind of orders.

Also I don't think inheriting from an abstract base class would be that high cost as technically the objects already derive from the Object base class. (Though I don't think this is completely equal to a custom base class.)

VB.Net can implement methods from an interface using a different name than the one specified in the interface but don't think the same goes for overriding abstract functionality.

Mikko Rantanen
Yes this was my first thought however I tend to shy away from base classes and lean more towards interfaces. But to have a shared function there is no other way to do this that I can see.Interface.. implement it in multiple placesBaseClass.. overload or wrap Protected properties ( for different names )"Logic Service"... still needs to understand what parameters are coming in so still need an abstraction interface or BaseClass.Was hoping others would have a way of deciding when one approach is best and when it's okay to have a baseclass ( since you can only have one. )
5x1llz
oh and I should add the reason for overloading and adding generics is so that you're not just restricted to the interface when calling this class from anywhere other than the shared function.to avoid a cast.. it just seemed like a lot to do to share one function across multiple classes
5x1llz