Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3438726
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:13:22+00:00 2026-05-18T08:13:22+00:00

For the past few days I’ve been writing classes that at first I thought

  • 0

For the past few days I’ve been writing classes that at first I thought adhered to the Command design pattern, but I’ve since modified them and am curious as to which pattern they really match up with (if any).

A basic example is a class I’m using to query the Facebook api to fetch a page’s feed. My class looks like this:

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;
        }

    }
}

I would then use the class like this:

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

From what I understand, a Command object should take a receiver object, which mine does not. And it seems that both my client and invoker are the same. Add to that the fact that I payload data with public variables and I feel like this definitely doesn’t match the Command pattern.

To further muddle things, I added some functionality to the Command superclass that let’s me keep track of errors that happen. For example:

    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;
        }

I would then test for errors with $com->hasErrors() and $com->getErrors()

So far this pattern has been working quite well for me. I know that the details of a design pattern aren’t always written in stone, and that it’s more important to solve a problem than worry about semantics, but I’m genuinely curious about this and want to see if I can improve my code (or if I’m somehow digging myself a grave).

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:13:22+00:00Added an answer on May 18, 2026 at 8:13 am

    Looks like the Command pattern to me. The client is the one who creates the Command, the initiator is the one who calls the execute method and the receiver is the one who implements the execute.

    Just because the client and initiator are the same in your instance doesn’t seem to change the pattern for me. I think the important part is that you create the command passing in the parameters in the constructor or by setting properties. The command can later be executed by some other object (the intitiator) simply by calling the execute method of the command interface – it doesn’t need to know the parameters at that stage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been having this really annoying thing happen the past few days, that has
I've been looking into codeigniter for past few days. It looks promising, but there
I've been fighting with this for the past few days, and am hoping that
I have been writing this Android application for the past few days and everything
This is something that has been driving me mad over the past few days.
For the past few days I've been working on an online game, a 2-player
For the past few days I have been trying to play any sound over
There have been several questions over the past few days about the proper use
I've been asking a question or two over the past few days of working
I've been fiddling with Redmine in the past few days and not 100% happy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.