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.
deleydSoftware EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.