I have a .net website written in C# and will make functionalities that other developers can use.
So I will make some default implementation and a developer can overwrite some methods
Example:
i have a class ShoppingCart and a class Product the class product haves a method getProductPrice
the shoppingcart will call the method getProductPrice for calculating the total price of cart
The ShoppingCart and Product are in the same project and i will give the developers the .dll so they can’t change the source code so we can update the assembly later
So they need to make a other project and extend the product class and overwrite the method getProductPrice so they can implement there own logic
The problem is that the shoppingcart will not call the extended method but the original
If we make already a extended project for the developers and the shoppingcart will call the extended method then we have a circular reference
because the extended product needs a reference to product and the shopping cart to the extended product
Partial classes also don’t works because we only can use partials within the same assembly
Does anyone have a suggestion ?
Thanks in advance.
You should mark all your
Productmethods as virtual:Then the developers who will take over later can inherit from the product and override the method:
Because
OverridenProduct(in my example above) inherits fromProduct, it can still be added into theProductcollection within yourShoppingCartclass.Just symantics I guess, but the ShoppingCart class’s method should probably be
GetTotalPrice()notGetProductPrice()as I’m assuming you’re getting the total cost of the products in the cart.