Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts

    Question Using Interfaces to design an application

    HI

    I am trying to implement a Short Message Service or as you call it Texting service for mobiles into my PHP application that will send sms to my customers using various SMS providers (the real case senario is diff but here I am trying my best to explain my question, so pls bear with this SMS example only).

    Now, I am told to follow design patterns (not sure which one as I am new to patterns) to integrate it.

    My SMS class should have the following methods

    PHP Code:
    <?php
    class Verizon
    {
            public function 
    __construct($apiKey){
                    
    // class constructor code...
            
    }

            public function 
    AddNumber(array $numbers)
            {
                    
    // ...
            
    }

            public function 
    Send()
            {
                    
    // ...
            
    }
    }
    Now, just like a verizon, i will have different providers in future like AT&T, Cellcom, T-Mobile US etc...and to use a provider we have to use their library through which we interact with their servers.

    So here are the questions:

    Q1. Is it really a good idea to have a different class for different providers? Means If i need to implement a new provider, I have to write a new class? If no, then what?

    Q2. How do I make use of interfaces in this case? (i am told to use interfaces)

    Q3. If you could please draft me a skeleton of the structure of the best way to implement with an interface, i will really appreciate that.

    Q4. Where do we load the third party library?




    many thanks in advance
    Last edited by phantom007; 08-05-2014 at 06:54 AM.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,344
    Thanks
    13
    Thanked 349 Times in 345 Posts
    Q1: yes. cf. Factory Pattern

    Q2: each of these classes must implement your interface and then in your code where you want to use one of these classes, check for the interface when you import (cf. Dependency Injection) the class

    Q3: that depends on how you want to use the class(es)

    Q4: it is likely that you need to use an Adapter (or maybe a Decorator) to use the third party libraries with your interface
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    Regular Coder
    Join Date
    Jun 2006
    Location
    UK
    Posts
    922
    Thanks
    302
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Dormilich View Post
    Q3: that depends on how you want to use the class(es)
    Thanks for your reply. I have structured the basic class in my initial post, could u please draft me just the skeleton so that its easy for me to understand what u just explained?



    Thanks

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,344
    Thanks
    13
    Thanked 349 Times in 345 Posts
    PHP Code:
    // note: methods should be named in camelCase
    interface SMS
    {
        
    // the method description (e.g. PHPDoc) here
        
    public function addNumbers(Array $numbers);

        
    // the method description (e.g. PHPDoc) here
        
    public function send();

    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •