25
Designing A Payroll System A Solution Daniel POP, Ph.D

Designing A Payroll System A Solution Daniel POP, Ph.D

Embed Size (px)

Citation preview

Page 1: Designing A Payroll System A Solution Daniel POP, Ph.D

Designing A Payroll System

A Solution

Daniel POP, Ph.D

Page 2: Designing A Payroll System A Solution Daniel POP, Ph.D

2

Analysis by Use Case

• It is the system’s behavior that we are creating, not the system’s data; system’s data is a consequence

• Use Cases (UC) are ways to capture system’s behaviour– Similar to user stories (in SCRUM/XP)

• For our system, the UCs, what customer wants, are:1. Add a new employee

2. Delete an employee

3. Post a time card

4. Post a sales receipt

5. Post a union service charge

6. Change employee details (e.g., hourly rate, dues rate, etc.)

7. Run the payroll for today

Page 3: Designing A Payroll System A Solution Daniel POP, Ph.D

3

UC #1: Add a New EmployeeDescription• A new employee is added by the receipt of an

AddEmp transaction. This transaction contains the employee’s name, address, and assigned employee number. The transaction has three forms:

• AddEmp <EmpID> "<name>" "<address>" H <hrly-rate>• AddEmp <EmpID> "<name>" "<address>" S <mtly-slry>• AddEmp <EmpID> "<name>" "<address>" C <mtly-slry> <com-

rate>

• The employee record is created with its fields assigned appropriately

• If the transaction structure is inappropriate, it is printed out an error message, and no action is taken.

Page 4: Designing A Payroll System A Solution Daniel POP, Ph.D

4

UC #1: Add a New EmployeeInferred model• Use Command pattern to model each possible

type of transaction • Enforces SRP

Page 5: Designing A Payroll System A Solution Daniel POP, Ph.D

5

UC #1: Add a New EmployeeInferred model • Q: What do the three transactions create? • A: They create three kinds of employee objects

Page 6: Designing A Payroll System A Solution Daniel POP, Ph.D

6

UC #2: Delete an Existing EmployeeDescription• Employees are deleted when a DelEmp transaction

is received. The form of this transaction is as follows :

• DelEmp <EmpID>

• When this transaction is received, the appropriate employee record is deleted.

• If the <EmpID> field is not structured correctly or does not refer to a valid employee record, the transaction is printed with an error message, and no other action is taken.

Page 7: Designing A Payroll System A Solution Daniel POP, Ph.D

7

UC #2: Delete an Existing EmployeeInferred model

Page 8: Designing A Payroll System A Solution Daniel POP, Ph.D

8

UC #3: Post a Time CardDescription• On receipt of a TimeCard transaction, the system

will create a time card record and associate it with the appropriate employee record:

• TimeCard <empid> <date> <hours>

• The system will print an appropriate error message and take no further action.

• The system will print an appropriate error message and take no further action.

Page 9: Designing A Payroll System A Solution Daniel POP, Ph.D

9

UC #3: Post a Time CardInferred model

Page 10: Designing A Payroll System A Solution Daniel POP, Ph.D

10

UC #4: Post a Sales ReceiptDescription• On receipt of the SalesReceipt transaction, the

system will create a new salesreceipt record and associate it with the appropriate commissioned employee:

• SalesReceipt <empid> <date> <amount>

• The system will print an appropriate error message and take no further action.

• The system will print an appropriate error message and take no further action.

Page 11: Designing A Payroll System A Solution Daniel POP, Ph.D

11

UC #4: Post a Sales ReceiptInferred model

Page 12: Designing A Payroll System A Solution Daniel POP, Ph.D

12

UC #5: Post a Service ChargeDescription• Service Charge may be pension contribution,

health system contribution, union contribution etc.

• On receipt of this transaction, the system will create a service-charge record and associate it with the appropriate union member:

• ServiceCharge <memberID> <amount>

• If the transaction is not well formed or if the <memberID> does not refer to an existing service member, the transaction is printed with an appropriate error message.

Page 13: Designing A Payroll System A Solution Daniel POP, Ph.D

13

UC #5: Post a Service ChargeInferred model

• Because memberID and empID are not the same, the system must be able to associate union members and employees.

• There are many ways to provide this kind of association, so to avoid being arbitrary, let’s defer this decision until later.

Page 14: Designing A Payroll System A Solution Daniel POP, Ph.D

14

UC #6: Change Employee DetailsDescription• Upon receipt of this transaction, the system will alter

one of the details of the appropriate employee record. There are several possible variations to this transaction:

• ChgEmp <EmpID> Name <name> Change employee name• ChgEmp <EmpID> Address <address> Change employee address• ChgEmp <EmpID> Hourly <hourlyRate> Change to hourly• ChgEmp <EmpID> Salaried <salary> Change to salaried• ChgEmp <EmpID> Commissioned <salary> <rate> Change to

commissioned• ChgEmp <EmpID> Hold Hold paycheck• ChgEmp <EmpID> Direct <bank> <account> Direct deposit • ChgEmp <EmpID> Mail <address> Mail paycheck• ChgEmp <EmpID> Member <memberID> Dues <rate> Put employee in a

specific service• ChgEmp <EmpID> NoMember Cut employee from service

• If the structure of the transaction is improper, <EmpID> does not refer to a real employee, or <memberID> already refers to a member, the system will print a suitable error and take no further action.

Page 15: Designing A Payroll System A Solution Daniel POP, Ph.D

15

UC #6: Change Employee DetailsInferred model

Lot of information in this UC:1. The fact that the type of employee is changeable

implies that the diagram inferred from UC #1 is invalid; the inheritance is not appropriate => need to use object composition instead; Strategy pattern is a good candidate for pay computation

2. The same approach can be used for method of payment (it is also changeable)

3. The same approach can be used for Service affiliation; but, because all these afiliations are optional, we’ll use a NoAffiliation class for this (see NullObject pattern)

• All these patterns enforces OCP principle in our design

Page 16: Designing A Payroll System A Solution Daniel POP, Ph.D

16

UC #6: Change Employee DetailsInferred model

Page 17: Designing A Payroll System A Solution Daniel POP, Ph.D

17

UC #7: Run The Payroll For TodayDescription• On receipt of the payday transaction, the system

finds all those employees that should be paid on the specified date. The system then determines how much they are owed and pays them according to their selected payment method. An audit-trail report is printed showing the action taken for each employee:

• Payday <date>

Page 18: Designing A Payroll System A Solution Daniel POP, Ph.D

18

UC #7: Run The Payroll For Today Inferred model• First, how does the Employee object know how to

calculate its pay?

Page 19: Designing A Payroll System A Solution Daniel POP, Ph.D

19

UC #7: Run The Payroll For Today Calculate the pay day • The system will

sum up an hourly employee’s time cards and multiply by the hourly rate.

• Similarly, the system will sum up a commissioned employee’s sales receipts, multiply by the commission rate, and add the base salary.

• For Salaried employee, the system will pay the fixed monthly amount

Page 20: Designing A Payroll System A Solution Daniel POP, Ph.D

20

UC #7: Run The Payroll For Today Digging ‘hidden’ abstractions• Some abstractions are easy to find; for example, from

“Some employees work by the hour” and “Some employees are paid a flat salary” we derived the PaymentClassification abstraction.

• Some others are “hidden”; for example, from “They are paid every Friday,” “They are paid on the last working day of the month,”, or “They are paid every other Friday.” we may derive the notion of Schedule of Payment, that is not specifically mentioned in requirement!

• One way of doing this is to compute whether a day is a pay day or not in the PaymentClassification classes

• …but this is violating 2 OOP principles: OCP and SRP

Page 21: Designing A Payroll System A Solution Daniel POP, Ph.D

21

UC #7: Run The Payroll For Today Digging ‘hidden’ abstractions• Instead, we’ll do like this

• What pattern did we use?

Page 22: Designing A Payroll System A Solution Daniel POP, Ph.D

22

UC #7: Run The Payroll For Today Affiliations model revisitedOld model New model(from UC #6)

• What patterns did we removed in the new model?

Page 23: Designing A Payroll System A Solution Daniel POP, Ph.D

23

Summary Final Design

– Command– Strategy

(*) Commands hierarchy is not depicted here

Page 24: Designing A Payroll System A Solution Daniel POP, Ph.D

24

Summary Java Sources

• This example has been (partially) implemented in Java

• Download the Java sources and binaries from the following address:

http://web.info.uvt.ro/~danielpop/dp/payroll.zip

• To run the example, extract the zip file and execute run.bat file

Page 25: Designing A Payroll System A Solution Daniel POP, Ph.D

25

The Big Conclusion Of This Course

Overreliance on tools and procedures and

underreliance on intelligence and experience are recipes

for disaster.