V
V
Vladislav Ross2013-04-04 08:38:35
PHP
Vladislav Ross, 2013-04-04 08:38:35

Suggest an OOP pattern for a task

I am writing something like a daemon in PHP that processes requests coming from the database without stopping.

The question is: how to organize the structure of the program? I want different checks to be applied to the ticket depending on the ticket type. Moreover, checks should be called at 3 stages: the application was received, processed, and left.

Those. there should be something like the events OnStart, OnProcessed, OnFinish, on which the verification functions are hung, which receive the application parameters as input. The order in which the functions are executed is not important to me.

It is assumed that the system administrator can configure these functions, so I cannot hard-link functions to order types in the code.

In principle, OOP is not an end in itself for me, I can do without it.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Sergey Beresnev, 2013-04-04
@sectus

The names of the methods themselves tell us that we can use the event approach .

S
StepEv, 2013-04-04
@StepEv

ChainOfResponsibility, Strategy, can be State

V
Vyacheslav Slinko, 2013-04-04
@KeepYourMind

For daemons, you can use reactphp.org - a cool asynchronous framework.

T
tyomo4ka, 2013-04-04
@tyomo4ka

If you do not need a distributed solution, but something simple, then the Observer pattern en.wikipedia.org/wiki/Observer_pattern is quite suitable . As a specific implementation, I can recommend the Symfony Event Dispatcher component symfony.com/doc/current/components/event_dispatcher/introduction.html .
If you want the queue to work asynchronously. The way already advised or react.php. Or if there is no problem with installing additional software, install some queue server (for example, ActiveMQ activemq.apache.org/ ) and work with it from PHP.

S
stalkerg, 2013-04-11
@stalkerg

This is what I don't like! No need to pull a pattern on the task! Take and solve the problem as logic tells you.
There is no pattern for every sneeze, and often a pattern can complicate a simple task.
And yes, if you can do without OOP (and you are sure that you will not need it further), then do not use it! OOP can also complicate or confuse a simple task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question