You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In class-based programming, the factory method pattern is a creational pattern which uses factory methods to deal with the problem of creating objects without specifying the exact class of object that will be created. This is done by creating objects via calling a factory method—either specified in an interface and implemented by child classes, or implemented in a base class and optionally overridden by derived classes—rather than by calling a constructor.
227
+
228
+
#### Example
229
+
230
+
```ruby
231
+
classVehicleFactory
232
+
233
+
defself.factory(klass)
234
+
{ :car => Car,
235
+
:boat => Boat
236
+
}[klass].new
237
+
end
238
+
end
239
+
240
+
classCar
241
+
end
242
+
243
+
classBoat
244
+
end
245
+
246
+
VehicleFactory.factory :car
247
+
```
248
+
249
+
#### Facade
250
+
251
+
The facade pattern (or façade pattern) is a software design pattern commonly used with object-oriented programming. The name is by analogy to an architectural facade.
252
+
253
+
A facade is an object that provides a simplified interface to a larger body of code, such as a class library. A facade can:
254
+
255
+
- make a software library easier to use, understand and test, since the facade has convenient methods for common tasks;
256
+
- make the library more readable, for the same reason;
257
+
- reduce dependencies of outside code on the inner workings of a library, since most code uses the facade, thus allowing more flexibility in developing the system;
258
+
- wrap a poorly designed collection of APIs with a single well-designed API (as per task needs).
0 commit comments