Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Im trying to create an SMS gateway .. I have a request coming in from a client (web form or API or database record) that I need to process and forward on to a 3rd Party API - or SMS provider. So that things would be simpler going forward I decided to create an interface that each provider implementation would implement :

interface SMSProvider
  public method sendSMS(sendTo,message)
  public method sendWakeup(sendTo)

I thought this would be my best way forward because then I wouldn't have to change my code when sending to a different provider - i knew that when i create my provider i just call the method to perform the function with the normal parameters and everything is good ... Well until I have a new provider that requires new parameters

new provider requires
  - sendTo
  - message
  - sendFrom
  - validityPeriod

So now what do i do ? how can i now use my interface ? when the new provider needs extra parameters ?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

The usual practice in this case is to wrap arguments of interface methods into abstract classes and have implementing classes instantiate certain variation of the abstraction. So,

interface SMSProvider
public method sendSMS(SMSMessage)
public method sendWakeup(WakeupMessage)

class SMSProvider1
public method sendSMS(Provider1SpecificSMSMessage)
public method sendWakeup(Provider1SpecificWakeupMessage)

class SMSProvider2
public method sendSMS(Provider2SpecificSMSMessage)
public method sendWakeup(Provider2SpecificWakeupMessage)

abstract class SMSMessage
string sendTo
string message

class Provider1SpecificSMSMessage :: SMSMessage
/*
fields from base class plus customizations
*/

class Provider2SpecificSMSMessage :: SMSMessage
/*
fields from base class plus customizations
*/

[Sorry, not sure what language you're dealing with]

share|improve this answer
    
+1 nice explanation thanks .. i'm using PHP. –  ManseUK Jan 25 '13 at 15:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.