« Home | Expense Calculator Started » | Hibernate Mappings & Encapsulated Collections » | My Desk » | Using Agile Practices » | Automated Tests are Great » | Changing Mindset » | Business Knowledge and Software Projects » | Reading Styles » | Java and Access Specifiers » | Why refactoring helps? »

Expense Calculator - Session 1

My first session.

The following was achieved:
  1. Set up of intellij idea
  2. Requriements 1 and 2
Requirement 1: We bhavdeep, deepak, surender go to albertsons. Buy worth 15$ (we r stingy). bhavdeep pays. the expense amt is shared equally among 3.

Steps: Write junit test case, it fails. Write code so test passes.

Classes: Transaction, ExpenseSheet, ExpenseLine, Money, Party.

  • process method in Transaction generates Expense sheet. Has if statements to find out if Party is payer / receiver and then calculate. Smell of Party heirarchy
  • other classes have relatively no behavior.
  • decision: for this requirement its good enuf but when moving to other requirements i will have to wear my refacotring hat before implemetnation
Requirement 2: Same as requirement 1. Except bhavdeep has no share in the expenses. He only paid for it. divided equally between deepak and surender.

Steps: Write junit test method, it fails, then write code to make it pass

Classes: Transaction, ExpenseSheet, ExpenseLine, Money, Party, NonParticipantPayer->Party, Receiver->Party

  • Refactored Transaction , Party classes to distribute behavior of ExpenseSheet generation
  • Heirarchy of Party created. Expense lines generation delegated to Party without conditional processing (claps)
  • Transactions for above 2 requirements are equitable and non equitable. But they can change at run time. So I need to use State pattern. Havent done the refactoring. But its necessary though as of now only getEqualParts method has conditional processing. Thus this forms my next refactoring before I move on for the next requirement implementation
  • Add more behavior into money class. Something like 5USd 3 times is 15USD should be done by money class. will make Party expense cacls simpler
Session 2

Current Class Diagram is [Click on the picture to see enlarged]:Posted by Hello

Links to this post

Create a Link