What design template?

Over the past few days, I have written classes that I initially thought were tied to the Command design pattern, but have since been modified, and I'm curious about which pattern they really correspond to (if any).

A basic example is a class that I use to request a Facebook api file to get a page feed. My class is as follows:

class FetchPageFeedCommand extends Command {

    public $feed;

    private $pageId;

    public function __construct($pageId) {
        $this->pageId = $pageId;
    }

    public function execute() {
        if ($feed = Facebook::api('/page/feed') /* psuedo code */ ) {
             $this->feed = $feed;
             return true;
        } else {
             return false;
        }

    }
}

Then I would use the class as follows:

$com = new FetchPageFeedCommand(12345);
if ($com->execute()) {
   $feed = $com->feed;
   print_r($feed);
}

From what I understand, the Command object should take a receiver object that I don’t have. And it seems that both my client and invoker are the same. Add to this the fact that I am passing data with public variables, and I feel that this is definitely not consistent with the Command pattern.

, Command, , . :

    public function execute() {
        if ($feed = Facebook::api('/page/feed') /* psuedo code */) {
             $this->feed = $feed;
             return true;
        } else {
             $this->addError('Could not fetch feed'); // Error management
             return false;
        }

$com->hasErrors() $com->getErrors()

. , , , , , ( - ).

+3
3

. - , , , execute, - , .

, , , . , , , , . - () execute - .

+3

.

+1

, , .

, .

:


class MyFacebookApi {
  function __construct(Facebook $fb)
  function getFeed()
  function sendWallpost($msg)
  function getError()
}
+1

Source: https://habr.com/ru/post/1776294/


All Articles