In search of a pattern for processing the sample values?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
42 views
Hi!

Think about the pattern processing sampling from a database.

In General, the problem in simplified form is this: there is a selection of some set of goods from the database, you need to handle the values for each item:

— to apply discounts

to apply filters to the product to the buyer

— all bonuses

— additional attributes depending on the situation

etc., etc.

Make class Items_pool and hang foreach for each case — the first thing that comes to mind, but I feel that it is ugly. Are there any best practice?
by | 42 views

4 Answers

0 like 0 dislike
I suggest Chain-of-responsibility pattern
\ren.wikipedia.org/wiki/Chain-of-responsibility_pattern
\r
If I correctly understood the task as a step-by-step execution of some action.
Thus each unit will be responsible for adding/subtracting anything from the "base" prices.
\r
And in order to control the sequence — use the abstract factory or factory method (Yes, they differ).
by
0 like 0 dislike
You pull all products from the database and then use filters?
by
0 like 0 dislike
Than not sets up the solution of the problem on the side of the SQL server?
by
0 like 0 dislike
That is too much logic goes in the model.
\r

Wash mandatory "chewing" the result is a declarative operation that will also lead to an increase in logic.
\r
Make class Items_pool and hang foreach for each case — the first thing that comes to mind, but I feel that it is ugly
\r

To apply the currency rate on the client side you need to loop the sample, and the solution of the problem with SQL is sufficient to ask the server the result times the rate.
\r
You know better, but it seems to me logical to create an individual query on the client side (for example using stored procedure if the number of attributes is strictly limited, otherwise, heard that can help Query Object, but I've never used) and get the "server ready" data.
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
4 answers
110,608 questions
257,186 answers
0 comments
36,674 users