Separating "Play, Pause, Stop" from "Load File & Save File" (C# WPF)

I'm designing an application which has a Model. The Model has Play(), Pause(), and Stop() methods, as well as LoadFIle(filename) and SaveFile(filename).

I'm feeling that perhaps one class should not be doing all of this, as it's become a large "God" class.

"Play, Pause, Stop" sound like they go together as "control", whereas "Load & Save" sounds like something else, which involves reading a file and setting state.

Let's say the Model class has an ElapsedTime property, and a StopTime property.

SaveFile() saves the StopTime value to a file. LoadFile() loads the StopTIme value from the file.

(There's probably a lot more being saved and restored too.)

There's a MasterLoop() method which is an endless loop that makes the program "go".

Play() calls Task.Run to launch this MasterLoop() on a thread.

Stop() terminates this MasterLoop() and resets ElapsedTime.

Pause() terminates this MasterLoop() but does not reset ElapsedTime.

The MasterLoop() may exit on its own if ElapsedTime reaches StopTime.

I actually have the whole demo thing working fine (there's a CancellationToken involved too). (And there's a View and VIewModel, so we can see what's going on; some buttons for Play, Pause, Stop; and some menu items for Save File and Load File.)

My concern is it's all in one big Model class; and I'm suspecting that LoadFile and SaveFile maybe don't belong in the Model. But it doesn't belong in the ViewModel either, as the ViewModel shouldn't be reading a file, and it shouldn't be reaching into the Model and manipulating variables.

The ViewModel does prompt for a file name; but once it gets the file name, it should hand that off to... what? The Model?

The Model also has Initialization code in it, which does a bunch of setup, making my Model class even larger.

How can I reorganize this?
  • State Variables (Elapsed Time, Stop Time).
  • MainLoop()
  • Play, Pause, Stop
  • Load FIle, Save File
Load File, Save File, and MainLoop() need to access StopTIme.
Play, Pause, Stop do not need to access StopTime.
Stop needs to access ElapsedTime to reset it.
MainLoop needs to access ElapsedTime.

It's so easy when it's all together in one large class. I'm really trying to learn something about how to handle a much larger project. This is just an imaginary application demonstrating the larger problem.
Who is Participating?
my advice would be to put them in the same namespace.class so they will all be consistent, however make each one independent to maintain modularity.  BBOM, or, Big Ball Of Mud programming is what it seems you're describing.

if the projects all reference the helper classes, you still have a DLL with the functionality you're seeking, just much easier to maintain.

it may look slim now, but ask yourself, will it grow?  what is the life of the application?  must it live forever?  either way, better programming models are separated, modular layers with specific duties.

only group like items that have the exact same attributes, which isn't what you're describing.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.