Skip to content

Commit 69e1b3b

Browse files
committed
Adds docs for decorators, null object pattern and single responsibility principle
1 parent eb89cc8 commit 69e1b3b

File tree

1 file changed

+68
-9
lines changed

1 file changed

+68
-9
lines changed

README.md

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,22 +148,81 @@ end
148148

149149
[Code](active_record)
150150

151-
### Presenters
152-
Coming soon...
151+
### Presenters || Decorators
152+
153+
In object-oriented programming, the decorator pattern (also known as Wrapper, an alternative naming shared with the Adapter pattern) is a design pattern that allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class.[1] The decorator pattern is often useful for adhering to the Single Responsibility Principle, as it allows functionality to be divided between classes with unique areas of concern.
154+
155+
#### Example
156+
157+
```ruby
158+
class UserDecorator
159+
attr_reader :user
160+
161+
def initialize(user)
162+
@user = user
163+
end
164+
165+
def email
166+
"The user email is: #{@user.email}"
167+
end
168+
169+
def birthdate
170+
"#{@user}".strftime("%b %d, %Y")
171+
end
172+
end
173+
```
174+
175+
#### References
176+
177+
- [https://en.wikipedia.org/wiki/Decorator_pattern](https://en.wikipedia.org/wiki/Decorator_pattern)
178+
- [https://github.com/drapergem/draper](https://github.com/drapergem/draper)
179+
- [http://railscasts.com/episodes/286-draper](http://railscasts.com/episodes/286-draper)
153180

154181
### Single Responsibility Principle
155-
Coming soon...
182+
183+
In object-oriented programming, the single responsibility principle states that every class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility.
184+
185+
### Example
186+
187+
```ruby
188+
class UserRegistration
189+
attr_reader :user
190+
191+
def initialize(user)
192+
@user = user
193+
end
194+
195+
def register
196+
#logic to handle registration for that user
197+
end
198+
199+
def success?
200+
#was the registration successful?
201+
end
202+
.
203+
.
204+
.
205+
end
206+
```
207+
208+
#### References
209+
210+
- [https://en.wikipedia.org/wiki/Single_responsibility_principle](https://en.wikipedia.org/wiki/Single_responsibility_principle)
211+
- [http://railscasts.com/episodes/398-service-objects](http://railscasts.com/episodes/398-service-objects)
212+
- [http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod](http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod)
213+
- [https://www.youtube.com/watch?v=Gt0M_OHKhQE](https://www.youtube.com/watch?v=Gt0M_OHKhQE)
156214

157215
### Null Object Pattern
158-
Coming soon...
159216

160-
### Factory
161-
Coming soon...
217+
In object-oriented computer programming, a Null Object is an object with defined neutral ("null") behavior. The Null Object design pattern describes the uses of such objects and their behavior (or lack thereof). It was first published in the Pattern Languages of Program Design book series.
162218

163-
### Facade
164-
Coming soon...
219+
#### References
165220

166-
### Fat Models, Skinny Controllers
221+
- [https://en.wikipedia.org/wiki/Null_Object_pattern](https://en.wikipedia.org/wiki/Null_Object_pattern)
222+
- [http://sudo.icalialabs.com/null-object-pattern/](http://sudo.icalialabs.com/null-object-pattern/)
223+
- [https://www.youtube.com/watch?v=9lv2lBq6x4A](https://www.youtube.com/watch?v=9lv2lBq6x4A)
224+
225+
### Factory
167226
Coming soon...
168227

169228
### CodeRetreat

0 commit comments

Comments
 (0)