Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mrbrunelli/terere-builder
My studies of Builder Pattern, Factory Pattern and Repository Pattern with Javascript
https://github.com/mrbrunelli/terere-builder
builder-pattern design-patterns factory-pattern javascript mocha repository-pattern terere unit-testing
Last synced: about 2 months ago
JSON representation
My studies of Builder Pattern, Factory Pattern and Repository Pattern with Javascript
- Host: GitHub
- URL: https://github.com/mrbrunelli/terere-builder
- Owner: mrbrunelli
- Created: 2021-09-03T10:24:03.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-09-07T15:18:15.000Z (over 3 years ago)
- Last Synced: 2023-03-07T14:48:34.202Z (almost 2 years ago)
- Topics: builder-pattern, design-patterns, factory-pattern, javascript, mocha, repository-pattern, terere, unit-testing
- Language: JavaScript
- Homepage:
- Size: 270 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Builder, Factory and Repository pattern with Javascript
> Util content: [dofacory.com/javascript/design-patterns](https://www.dofactory.com/javascript/design-patterns)### Builder pattern
* Useful for creating custom behaviors, using methods with descriptive names.
* It's a lot like a production line, where each employee performs a single function.##### Example
```js
myBuilderFunction
.stepOne()
.stepTwo()
.stepThree()
.stepFour()
.finish()
```### Factory pattern
* Useful for concentrating instance creation in one place.
* Gives the possibility to crate some logic when creating an instance.##### Example
```js
function createOjbInstance(optionalParam) {
const param = optionalParam || "I am a default param"
return new MyClass(param)
}const objOne = createObjInstance()
const objTwo = createObjInstance()
const objThree = createOjbInstance("I am an optional parameter")
const objFour = createOjbInstance()
```### Repository pattern
* Useful for abstracting data persistence.
* Methods have descriptive names (find, findById, findByName, create, save, delete, remove etc).##### Example
```js
const myRepository = new MyRepositoryClass()myRepository.save({ id: "123abc", fieldOne: "one", fieldTwo: "two" })
myRepository.save({ id: "456dfg", fieldOne: "three", fieldTwo: "four" })const allRepositoryData = myRepository.find()
// [{ id: "123abc", fieldOne: "one", fieldTwo: "two" }, { id: "456dfg", fieldOne: "three", fieldTwo: "four" }]
```## What the hell is Tereré?
#### Practically an iced tea with water or juice
![](.github/terere.png)