Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Design patterns for event-driven logic

I'm developing a desktop application which depends on the XML data it receives from a server. There are several files, needed to be downloaded at different time.

A number of data structures is populated with parsed data. The correspondence between files and data structures isn't 1-to-1, as a matter of fact may be rather complicated.

Application states and transitions between states depends on contents (and their availability at the moment) of those pieces of downloaded information.

Obscure spagetti code handles all the download events, and interdependences.

I've been working for a while on some pattern to work with it in a more uniform way, but thought that the developer community has already figured out the most appropriate practices and patterns. Does anyone know of any?

like image 407
Maleev Avatar asked Aug 31 '25 10:08

Maleev


1 Answers

When you have states you will definitely need State Pattern. When you have complex rules regarding state transitions and different BL connected to this states this is the best way to go.First draw state diagram, and after that it is easy to write needed classes.

I must also agree with John for Observer patter, you could use it to make needed dependency inversion, and handle state transitions easily.

In your case you can put all BL into State Classes and process when system hits that State, you will have code separation and no spaghetti code... Code will follow and execute BL according to state transitions.

like image 83
zidane Avatar answered Sep 03 '25 05:09

zidane