3

I'm refactoring a huge WPF application whose complexity stems from the way it deals with flow control. It has a lot of "tiny business rules" that make it really difficult to make a modification without breaking something. These rules are things like

If the window mode is foo but this is the first time they've pressed this button and the user has a certain role, show this, else validate another thing and show that, else show another thing.

I've thought about creating a lot of different classes for validation and keeping the global state but I'm not sure if there's a design pattern or something focused on dealing with this kind of situation.

Doc Brown
  • 199,015
  • 33
  • 367
  • 565
Pepedou
  • 133
  • 5
  • Possible duplicate of [Style for control flow with validation checks](http://programmers.stackexchange.com/questions/148849/style-for-control-flow-with-validation-checks) – gnat Jul 19 '16 at 17:08
  • 4
    If you're not already doing so, a Model-View-ViewModel (MVVM) approach eases this problem considerably. See http://www.markwithall.com/programming/2013/03/01/worlds-simplest-csharp-wpf-mvvm-example.html – Robert Harvey Jul 19 '16 at 17:27

1 Answers1

3

One approach that might fit is a finite state machine. There are tools that help you build and visualize them but you can also model it with standard OOP practices.

JimmyJames
  • 24,682
  • 2
  • 50
  • 92