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 ?

1 Answer 1


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]


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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