The formal semantics of an object-oriented programming language include an encapsulated state . Is there a precedent for encapsulating a potential change preceding a state change? Although the following examples are in PHP, please also think that the agnostic language is in your answer.
Background
I have an object Clientwhose task is to send requests and receive responses from the server, and this is used to change the state of an object that is on another server by calling the API. There are several Url, one with an endpoint create, and the other with an endpoint update. The problem is that it updatecan be used to update several different elements inside a given object, each of which requires different parameters.
Level objects
Imagine objecthaving the following objects:
- ImageLayer
- BackgroundLayer
- Textlayer
- AudioLayer
- (H) Layer
To change ImageLayer, the API requires:
- Identifier
- URL of the new image
To change TextLayer, the API requires:
- Identifier
- What do you change about this (is it font, size, text content?)
- New value
, , id , AudioLayer:
Client::updateImageLayer(), Client::updateTextLayer(), , Client (N)Layer .
Client::updateLayer(Layer $layer, array $values), , .
, , : Change.
, Change, - , Client, API?
interface Change
{
public function isValid();
public function getChanges();
}
class ImageLayerChange implements Change
{
protected $url;
protected $id;
public function __construct($id, $url)
{
$this->url = $url;
$this->id = $id;
}
public function isValid()
{
}
public function getChanges()
{
return array($this->id, $this->url);
}
}
, Client Change, ChangeSet, , , isValid() getChanges() API .