From: James French Date: 2012-04-05T21:58:32+09:00 Subject: Design pattern question --_000_950618E0D00138499BE7CC487EBF646D70EF858A2AWOODCHUCKNMlo_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi group, I wonder whether you could give me any advice on how to structure some code= ? Its pretty simple really. I want to be able to call an API like this: SourceControl.checkout SourceControl.update Etc I want to be able to plugin different source control systems that conform t= o the API. My initial thought was just to go with a simple C++ style wrapper/delegate = approach: module SourceControl def self.checkout(repository, dest, options=3D{}) @sourceControl.checkout(repository, dest, options) end def self.update(path, options=3D{}) @sourceControl.update(parth, options) end class SourceControlAPI def checkout(repository, dest, options=3D{}) end def update(path, options=3D{}) end end end But I bet there is a nicer way, perhaps without having to duplicate the API= ? Any pointers appreciated. Cheers, James --_000_950618E0D00138499BE7CC487EBF646D70EF858A2AWOODCHUCKNMlo_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi group,

 

I wo= nder whether you could give me any advice on how to structure some code?

 

= Its pretty simple really. I want to be able to call an API like this:<= /o:p>

 

Sou= rceControl.checkout

SourceControl.update=

 

Etc

 

I want to be able to plugin different source control systems that = conform to the API.

 

My initial thought was just to go with a simple C++ s= tyle wrapper/delegate approach:

&nb= sp;

module SourceControl

 

def self.checkout(= repository, dest, options=3D{})

  @= sourceControl.checkout(repository, dest, options)

end

 

def self.update(path, options=3D{})

  @sourceControl.update(parth, options)

end

 <= /p>

class SourceControlAPI

 

  def checkout(= repository, dest, options=3D{})

  e= nd

 

  def update(path, options=3D{})

  end

 

end

 

end

&n= bsp;

But I bet there is a nicer way, perhaps = without having to duplicate the API?

 

Any pointers appreciated.=

 

Cheers,<= br>James

= --_000_950618E0D00138499BE7CC487EBF646D70EF858A2AWOODCHUCKNMlo_--