views:

91

answers:

2

I have a winforms projects and we use the command pattern. We are trying to clean up our directory structure and make it consistent.

We are trying to decide if we should have a root commands folder or not. What do you think is better for a directory structure?

Project
--Commands
----AddCommand
----SubtractCommand
----InsertCommand
----DeleteCommand

or

Project
--Calculation
----AddCommand
----SubtractCommand
--Database
----InsertCommand
----DeleteCommand

A: 

Personally I like the second option but I think that you could also do something like this:

Project
-Commands
--Calculation
----AddCommand
----SubtractCommand
--Database
----InsertCommand
----DeleteCommand

Just my 2 cents

Nathan W
+2  A: 

It seems like the general question is whether you want to categorize by actions/verbs (i.e. a Commands folder) or by targets/nouns (folders for Database, Calculation, etc). Whichever route you take, you might try to be consistent (take the same approach with Views and Widgets as you do with Commands, etc).

A few considerations I can think of:

  • Are there other things that would also go in the Project/Database/etc folders, or only commands? If only commands, it might simplify things to just have a Commands folder, so you don't have to decide on a good top-level folder for each new command. For instance, where do you put a command that does Calculations on Database values?

  • If you're going to have a large number of commands (where "large" is somewhat ill-defined), having an additional level of directories might be nice.

In my experience, the question of how to organize code is always irritating. If all else fails, you should just pick an option and go with it, and rearrange later if you decide you made the wrong choice.

Charlie