Let's say we have a website with products. We have a method that Product::getProducts
returns an array of products.
Then a manager came to us and said: we want to make promotions on the site (discounts, sales). Products will be attached to each promotion. We wrote a methodAction::getProductsByActionId(actionId)
Then the manager came to us again and said that we needed more articles to which the goods were attached. Let's add a method Article::getProductsByArticleId(arcticleId)
.
You say - let's make 1 method with parameters. Ok, we'll get to that.
And then attention: a manager came to us and said - we want to be able to disable products on the site. Those. it is necessary to add an active flag for products, which has the value true / false. Products with the false flag should not be displayed on the site.
Bottom line: we need to find all the places in the code that get products and add logic everywhere so that only products with the active = true flag are returned. Those. 3 methods need to be corrected:
Product::getProducts,
Action::getProductsByActionId(actionId),
Article::getProductsByArticleId(arcticleId)
The fact that we need to correct the code in the wrong place is striking errors - in some place they forgot to correct it.
Well, let's make it so that we only have 1 place to get goods from. Then there will be no such error.
: , : Product::getProducts(actionId = null, articleId = null)
. , Product::getProducts
, articleId, Action::getProductsByActionId(actionId)
, ..
, , .. .
: . . , , Store::getProducts
— - , . - Product::getProducts
. ( , , - - ), - .
: : , active. . . 1 — Product::getProducts
active=true.
. — . 1 , — . . , Product::getProducts
-, active . 1 .
1 — , — . — -, - . . , — .
UPD:
, 1 : Product::getProducts, Product::getProductsV2, Product::getProducts , , , .
: , 1 private Product::getProducts. public , , .. - Product::getProductsForCatalog, - Product::getProductsForAction, : Product::getProductsForArticles, Product::getProductsForStore .. - 1 , 1 . 1 ( ), .