CSC/ECE 517 Fall 2009/wiki3 1 kp: Difference between revisions
Jump to navigation
Jump to search
Wikimaster (talk | contribs) |
Wikimaster (talk | contribs) |
||
Line 20: | Line 20: | ||
} | } | ||
Although, the above code looks right by providing | Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour encapsulation.It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class. | ||
==See also== | ==See also== | ||
==References== | ==References== | ||
==External Links== | ==External Links== |
Revision as of 00:43, 13 November 2009
Anti-patterns
Overview
Known classifications
Software design anti-patterns
Object-oriented design anti-patterns
- Anaemic Domain Model
Separating the business logic from the Domain Model is termed as Anaemic Domain Model.One of the prime reason for it being popular is, it provides separation of logic and data. To site few places this is used are Java's Entity beans and .Net's three layered service application. A short example for Anaemic Model is given below,
class BankAccnt { private double balance; public void setBalance(double balance) { this.balance = balance; } class AccntService { public void debit(Account account, double amount) { account.setBalance(account.getBalance() - amount); } }
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour encapsulation.It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.