Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I originally asked this on SO, where it was closed and recommended that I ask it here instead. I'm trying to figure out how to group all the functions necessary for my project into classes. The goal of the project is to execute the following process:

  1. Get the user's FTP credentials (username & password).
  2. Check to make sure the credentials establish a valid connection to the FTP server.
  3. Query several Sharepoint lists and join the results of those queries to create a list of items that need to have action taken on them.
  4. Each item in the list has a folder. For each item:
    • Zip the contents of the folder.
    • Upload the folder to the FTP server using SFTP
    • Update the item's Sharepoint data.
  5. Email the user an Excel report showing, e.g.,
    • Items without folder paths
    • Items that failed to zip or upload

Steps 2-5 are performed on a periodic basis; if step 2 returns an invalid connection, the user is alerted and the process returns to step 1. If at any point the user presses a certain key, the process terminates.

I've defined the following set of classes, each of which is in its own .cs file:

SFTP: file transfer processes

DataHandler: Sharepoint data retrieval/querying/updating processes. Also makes and uploads the zip files.

Exceptions: Not just one class, this is the .cs file where I have all of my exception classes.

Report: Builds and sends the report.

Program: The main class for running the program.

I recognize that the DataHandler class is a god object, but I don't have a good idea of how to refactor it. I feel like it should be more fine-grained than just breaking it into Sharepoint, Zip, and Upload, but maybe that's it.

Also, I haven't yet worked out how to combine the periodic behavior with the "wait for user input at any point in the process" part; I think that involves threads, which means other classes to manage the threads...

I'm not that well-versed in design patterns, but is there one that fits this project well?

If this is too big of a topic to neatly explain in an SO answer, I'll also accept a link to a good tutorial on what I'm trying to do here.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

@Emmad has hit the nail on the head on the note about Single Responsibility.

If you follow a Behaviour Driven approach to class design (ignoring all the unit testing stuff for the moment and thinking more along the lines of the Behaviours which your program needs to support), you might start with entities which represent individual areas of functionality, for example, you may end up with individual classes for each of the following

  • User Input Handler
  • User Credentials (simple data object or struct?)
  • User Credentials Validator
  • Sharepoint Query
  • Folder Compressor
  • Folder Sender
  • FTP Connection
  • Sharepoint Updater
  • Sharepoint Connection
  • Report (simple data object or struct?)
  • Report Builder
  • Report Sender
  • Email Connection

The reason for using these as a starting point is not necessarily to model exactly what will appear in your final code, but to provide you loose coupling until you have some code in front of you which gives you a better understanding of the problem and how everything fits together.

In general, it is easier to add complexity to a simple class than it is to simplify something which started out complex in the first place; Similarly, if you end up with a working solution and decide that some of the classes should be merged together, then this is also easier to do than splitting up a single class which had started out doing too much.
(Remember that problems are seldom as trivial as they seem at first, especially not when you start thinking about error flow control, debug logging, disposable resources, etc - something which starts out as "Oh, we can do this with one line of code" might turn out to be a lot more than one line)

Doing this you might also notice patterns in the kinds of method names you're using which may lend themselves to interfaces and abstractions which previously weren't obvious from looking at the original problem.

share|improve this answer
add comment

DataHandler, is not following SRP. It is doing several different things. You may be missing a class (or more) that would be responsible for maintaining user credentials(create, update, delete) of a user. Also, you may want to handle Excel reporting separate from Emailing the report (2 classes not 1) since reporting is the process of sending an Excel report, these are 2 different responsibilities.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.