Naming a class that processes orders

Posted by p.campbell on Programmers See other posts from Programmers or by p.campbell
Published on 2012-09-29T18:39:03Z Indexed on 2012/09/29 21:49 UTC
Read the original article Hit count: 238

Filed under:
|
|

I'm in the midst of refactoring a project. I've recently read Clean Code, and want to heed some of the advice within, with particular interest in Single Responsibility Principle (SRP).

Currently, there's a class called OrderProcessor in the context of a manufacturing product order system.

This class is currently performs the following routine every n minutes:

  • check database for newly submitted + unprocessed orders (via a Data Layer class already, phew!)
  • gather all the details of the orders
  • mark them as in-process
  • iterate through each to:

    • perform some integrity checking
    • call a web service on a 3rd party system to place the order
    • check status return value of the web service for success/fail
    • email somebody if web service returns fail
  • constantly log to a text file on each operation or possible fail point

I've started by breaking out this class into new classes like:

  • OrderService - poor name. This is the one that wakes up every n minutes
  • OrderGatherer - calls the DL to get the order from the database
  • OrderIterator (? seems too forced or poorly named) -
  • OrderPlacer - calls web service to place the order
  • EmailSender
  • Logger

I'm struggling to find good names for each class, and implementing SRP in a reasonable way.

How could this class be separated into new class with discrete responsibilities?

© Programmers or respective owner

Related posts about naming

Related posts about refactoring