Você está na página 1de 4

Symptoms of Rotting Design

1. 2. 3. 4. Rigidity Fragility Immobility Viscosity

i. ii.

Difficult to Change Ripple effect (chasing the thread through the application, module after module)

Rigidity:

Fragility:
i. ii. iii. iv. Conceptually irrelevant pieces breaking in multiple places every time some change is made in one place Lack of localized effect Such software is impossible to maintain. Every fix makes it worse, introducing more problems than are solved Managers and Customers have a feeling that Developers have lost control over the project

Immobility:
i. ii.

iii.

Inability to reuse software The work and risk required to separate the desirable parts of the software from the undesirable parts are too great to tolerate Software is simply rewritten instead of reused

Viscosity:
i. ii. iii. It is easy to do the wrong thing, but hard to do the right thing When the design preserving methods are harder to employ than the hacks, then the viscosity of the design is high Viscosity of environment comes about when the development environment is slow and inefficient

OO Design Principles
1. 2.

3.

Single Responsibility Principle (SRP) Open Closed Principle (OCP) Tell Dont Ask

Single Responsibility Principle (SRP): There should be only one reason for a class to change.
Example: Non-SRP:

public class { public public public public public public public public }

Customer string Name string DeliveryAddress string PhoneOrMobile DateTime InvoiceDate int GetNumberOfPurchasedItems() double GetItemUnitPrice(string itemId) GetTotalPriceOfPurchasedItems() List<string> GetPurchasedItems()

SRP:
public class { public public public } public class { public public public public } Customer string Name string Address Invoice CustomerInvoice Invoice DateTime InvoiceDate int GetNumberOfPurchasedItems() GetTotalPriceOfPurchasedItems() List<Item> GetLineItems()

public class Item { public double GetItemUnitPrice(string itemId) }

Open Closed Principle (OCP): A module should be open for extension and closed for
modification
public class BankAccount { public virtual string GetMyInfo() { return "Account Number: " + accountNumber + ", Balance: " + balance; } } public class CheckingAccount : BankAccount { public override string GetMyInfo() { return base.GetMyInfo() + ", Service Charge: " + serviceCharge; } } public class SavingsAccount : BankAccount { public override string GetMyInfo() { return base.GetMyInfo() + ", Interest Rate: " + interestRate; } } public static void Main(string[] args) { CheckingAccount chk1 = new CheckingAccount("Chk-001", 4.5); CheckingAccount chk2 = new CheckingAccount("Chk-002", 5.5); SavingsAccount sv1 = new SavingsAccount("Sv-001", 3.5); SavingsAccount sv2 = new SavingsAccount("Sv-002", 2.5); chk1.Deposit(2000); chk2.Deposit(3400); sv1.Deposit(35000); sv2.Deposit(12000); chk1.Withdraw(1000); sv2.Withdraw(200); List<BankAccount> accounts = new List<BankAccount>(); accounts.Add(chk1); accounts.Add(chk2); accounts.Add(sv1); accounts.Add(sv2); Display(accounts); Console.ReadKey();

private static void Display(List<BankAccount> accountList) { foreach (BankAccount account in accountList) { Console.WriteLine(account.GetMyInfo()); } }

Tell, Don't Ask (Hollywood Principle): Don't call us we will call you
Example : Procedural Pattern: string fullName = customerObj.FirstName + + customerObj.MiddleName + + customerObj.LastName; Object-Oriented Pattern: string fullName = customerObj.FullName;

Note: This document is a slim version of Software Design Principles


Slide (By Naresh Jain)

Você também pode gostar