-
Notifications
You must be signed in to change notification settings - Fork 19
Backend Pattern Decorator
Ferris Tseng edited this page Dec 13, 2019
·
5 revisions
A decorator allows you to add functionality to a class without changing the behavior of all instances of that class. 1
A decorator is especially good for separating presentation logic from a model.
app/decorators
N/A
A decorator should primarily be used to separate presentation logic from a
model. A concern can also be used to encapsulate,
shared business logic, but could pollute the namespace of methods for the model
(e.g. a full_name
method on the concern could clash with one already on the
model).
- 1: https://www.thegreatcodeadventure.com/rails-refactoring-part-iii-the-decorator-pattern/
- https://thoughtbot.com/blog/tidy-views-and-beyond-with-decorators
Pattern | Description |
---|---|
Model | Typically used to present a model |