MattWoberts wrote:
wayne wrote:
I might be wrong but as far as i know is it impossible to put code in a Interface.
Interfaces are purely a representation of methods, events and proeprties that is suppose to be implemented by classes with non common anchestors or classes with common ancestors but with non common functionality wanting to have common functionality implementation.
Yep,. interfaces cannot contain code, just "contracts". But the SiteManager is not an interface - I assumed it was the "BL" - Dave?
It sits in the business layer and provides a level of abstraction. I may have a manager type class in my web applications that oversee the dishing out of important business objects. Sometimes I don't want the client to create the business objects directly, because I may change them or may not know which one I will be using at that time.
The example I previously gave was contrived. A better example may be my e-commerce framework where I have a StoreManager class. It sits in the business layer. If a page (presentation layer) on the website needs the product catalog service (business object), he doesn't create it directly, he asks the store manager.
IProductCatalog catalog = StoreManager.GetProductCatalog();
Same thing with the shopping cart. If a page on the website needs the shopping cart, it has to ask the StoreManager.
IShoppingCart cart = StoreManager.GetShoppingCart();
The presentation layer has to interact with the product catalog and shopping cart through the public interface.
Inside those StoreManager methods, like GetShoppingCart(), I am running some business logic (Wayne may suspect differently
) trying to figure out which class to create and return as well as possibly populating ctor parameters that the presentation layer does not need to know about. Like the Abstract Factory design pattern I guess.
However, the nice thing is that I don't have to change my presentation layer (pages) if ShoppingCartBasic is returned instead of ShoppingCartPro. I only care about the service contract - IShoppingCart.
I also do this same interface stuff with credit card processing and shipping. Some customers choose online credit card processing and some don't. Or perhaps the payment gateway is down. You decide which class to return inside StoreManager.GetCreditCardProcessor() based on some parameters separate from the user interface.
I am sure Frans could show me the err of my ways, but it has worked out fairly well. Hope this helps