

Lastly, the client for CustomerServiceManagerclass will only call GetCustomerDetails method, pass the lastName and should not care about how and where the data is coming from. Of course we need identical stored procedures in all participating databases. Now if we have a new customer detail database we can just add a new class that extends BaseDataAccess and provides its database object. I havent shown the Dependency Injection to keep it simple as its already getting complicated now.

New SavingsAccountCustomerDataAccess(new DatabaseFactory())įoreach (IDataAccess nextDataAccess in dataAccess)Ĭustomer customerDetail = nextDataAccess.GetDetails(lastName) New CurrentAccountCustomerDataAccess(new DatabaseFactory()), New MortgageCustomerDataAccess(new DatabaseFactory()), Public IEnumerable GetCustomerDetails(string lastName) In the Business layer we have CustomerServiceManager class that returns the customer detials to its clients.īUSINESS LAYER: public class CustomerServiceManager : ICustomerServiceManager, BaseServiceManager Once these 3 data access classes are set, now we draw our attention to the client. This.Database = factory.GetSavingsAccountCustomerDatabase() Public SavingsAccountCustomerDataAccess(IDatabaseFactory factory) SAVINGS ACCOUNT CUSTOMER DATA ACCESS: public class SavingsAccountCustomerDataAccess : BaseDataAccess This.Database = factory.GetCurrentAccountCustomerDatabase() Public CurrentAccountCustomerDataAccess(IDatabaseFactory factory) This.Database = factory.GetMortgageCustomerDatabase() ĬURRENT ACCOUNT CUSTOMER DATA ACCESS: public class CurrentAccountCustomerDataAccess : BaseDataAccess Public MortgageCustomerDataAccess(IDatabaseFactory factory) MORTGAGE CUSTOMER DATA ACCESS: public class MortgageCustomerDataAccess : BaseDataAccess This abstract class has a common method "GetDetails" for all 3 databases which is extended by each of the database classes as shown below use the database object to call the stored procedure to retirve the customer detials Public Customer GetDetails(string lastName) / Enterprise library data block Database object. Now we may get more than 1 customer detail from those 3 databases against given last name.īUSINESS MODEL LAYER: public class CustomerĭATA ACCESS LAYER: public interface IDataAccessĪbove interface is implemented by the abstract class public abstract class BaseDataAccess : IDataAccess Scenario: Suppose we have 3 databases (Mortgage Customers, Current Accounts Customers and Savings Account Customers) that provide customer data and we need customer details for given customer's last name. NET word and is closely resembles Java and C++.
SOLID PRINCIPLES TUTORIAL CODE
In the sample code I have used C# as it is the most widely used language in. You can use any IDE and OOP language to implement S.O.L.I.D Principles.

Since the Documentation for solid-principles is new, you may need to create initial versions of those related topics. It should also mention any large subjects within solid-principles, and link out to the related topics. By participating to this training you will get a deep understanding of the object oriented design principles also known as the SOLID Principles.You will understand how by following them you can structure your code in a way that you will enjoy working on it, long after the first lines were written in your project. So it's violate the ISP principle.This section provides an overview of what solid-principles is, and why a developer might want to use it.

In the SmsMessage we don't need BccAddresses and Subject, but we forced to implement it because of IMessage interface. ISP violation : public interface IMessage Without talking unnecessary things let's jump into the code. Here we give an example of ISP violation and then refactor that violation. A client should never be forced to implement an interface that it doesn't use or client shouldn't be forced to depend on methods that they don't use. The principle states that no client should be forced to depend on methods that it doesn't use.
