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 1014663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:17:01+00:00 2026-05-16T10:17:01+00:00

I’m creating an interface for PickupPoints, Each pickup point needs to be able to

  • 0

I’m creating an interface for “PickupPoints”, Each pickup point needs to be able to return all pickup points found and the pickup point details and maybe in the future more information. That’s okay with the code below:

<?php

interface iPickupPoint
{
    public function getPickupPoints($countryCode, $postalCode, $city);
    public function getPickupPointDetails($pickupPointId);
}


class PickupPoint1 implements iPickupPoint{
    ...
}

class PickupPoint2 implements iPickupPoint{
    ...
}

The problem is that I don’t want to call the classes of PickupPoint1, PickupPoint2, .. them selves.
I want a class like PickupPoint(PickupPointType) so I just want to give the type of pickup point and the types need to be PickupPoint1, PickupPOint2, ..

How can this be done? Is this even possible? Is this a best practice?

  • 1 1 Answer
  • 0 Views
  • 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-16T10:17:02+00:00Added an answer on May 16, 2026 at 10:17 am

    What you are describing is the Factory pattern, so yes, it’s a best practice.

    http://www.devshed.com/c/a/PHP/Design-Patterns-in-PHP-Factory-Method-and-Abstract-Factory/

    Your factory itself does not need to implement the interface. It could be a static class or even a function:

    class PickupPointFactory{
      public static function create($type){
        /* your creation logic here */
        switch ($type) {
          case "PickupPoint1" : 
            $obj = new PickupPoint1(); 
          break;
          case "PickupPoint2" :
            $obj = new PickupPoint2();  
          break;
        }
        return $obj;
      }
    }
    
    $newPoint = PickupPointFactory::create("PickupPoint2");
    

    The creation logic can be a lot more generic to avoid changing the factory every time you add a class to your application:

    class PickupPointFactory{
      public static function create($type, $options){
        /* your creation logic here */
        if(file_exists(dirname(__FILE__).'/'.$type.'.class.php')) {
          require_once(dirname(__FILE__).'/'.$type.'.class.php');
          $obj = new $type($options);
          return $obj;
        } else {
          throw new Exception('Unknown PickupPoint type: '.$type);
        }
      }
    }
    
    $newPoint = PickupPointFactory::create("PickupPoint2", array());
    

    This one is assuming you are creating your classes in files named “PickupPoint1.class.php” in the same directory that the factory is, and that the constructor in your classes need only one parameter.

    I didn’t test this code, so some bug might have slipped in.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.