V
V
vasIvas2014-08-23 15:24:43
PHP
vasIvas, 2014-08-23 15:24:43

What is the name of the pattern that prepares the arguments?

There are two objects with public methods. Today, the first one returns a string, the second one takes it, and tomorrow the first one returns an array of strings, while the second one still takes a string.
What is the name of the design pattern that is designed to deal with changes like this?
Added:

var Test = function(){
  //...
};

Test.prototype.input = function(message){
  console.log(message);
};

var AdapterGreeting = function(){
  //...
};

AdapterGreeting.prototype.adapt = function(args){
  var str = 'Hello ';

  return str + args + '!';
};

var AdapterListing = function(){
  AdapterGreeting.call(this);
};

AdapterListing.prototype = Object.create(AdapterGreeting.prototype);
AdapterListing.prototype.constructor = AdapterListing;

AdapterListing.prototype.adapt = function(args){
  var length = args.length;
  var count = 0;
  var row = '';

  while(count < length){
    row += 'Item - ' + args[count++] + ';' + '\n';
  }

  return row;
};


var test = new Test();
var adapterGreeting = new AdapterGreeting();
var adapterListing = new AdapterListing();

test.input(adapterGreeting.adapt('World'));
test.input(adapterListing.adapt(['1', '2', '3']));

jsfiddle.net/x1guaqbc

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WebSpider, 2014-08-23
@vasIvas

Most likely it is an adapter , well, or a facade. They're alike

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question