mardi 14 février 2017

Identifying two design patterns?

I've got two approaches to implement handling of classes, and I'm curious if there are design pattern names for these two.

First implementation - self persisting class:

Car c;
c.load(1);
c.Model = "Ferrari";
c.Color = "Yellow";
c.drive();
c.save();

In this approach the class contains both properties, and methods. It has all it business logic inside the same class, and knows how to load and persist itself.

Is there a design pattern name for this approach?

And the second implementation - a controller agent and a data object;

CarAgent carAgent;
Car c = carAgent.load(1);
c.Model = "Ferrari";
c.Color = "Yellow";
carAgent.drive(c);
c = carAgent.save(c);

This approach uses two classes. The Car class is a "stupid" datacarrier class with only properties. No business logic in it. All work being done to the Car class is done using a CarAgent. It contains all business logic, but does not have any internal state or properties.

Does this also have a design pattern name?

Aucun commentaire:

Enregistrer un commentaire