GithubHelp home page GithubHelp logo

devcorpio / principles-of-package-design Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 1.0 46 KB

Repository that contains code in node.js from the book Principles of Package Design by Matthias Noback

License: MIT License

JavaScript 100.00%
nodejs javascript solid-principles software-engineering software-design packages

principles-of-package-design's Introduction

Principles of Package Design

Principles of Package Design

Principles of Package Design is a book written by Matthias Noback

The book code examples are written in PHP and the tools that appears in it are from the PHP community.

Goal of this repository

Node.js

I would like that people that works using Node.js could enjoy of the knowledge that this book offers to its readers. Therefore I going to use Node.js to write the code examples and I going to use tools typically related with it. ๐Ÿ˜

The style of the code and the chosen tools are 100% my decision. (The good and the bad parts! ๐Ÿ˜š)

How study the repository

  1. For every chapter of the book has I created a directory where appears the final version of the code in the mentioned chapter.

  2. Every commit has a reference to the chapter related. Any change I needed to do has a commit, with the objective of follow the flow of the book.

Note: If you want to open the links in another tab, just do a CTRL+click on the link.

Chapters

  1. The Single Responsibility Principle

    git commits done during the chapter :shipit:

    - Initial commit
    - update README
    - In order to commit formatted code I installed prettier, pretty-quick and husky
    - adding gitignore file
    - adding prettier config file
    - creating confirmationMailMailer using a factory function with too many responsibilities
    - extracting the creation of confirmation mail responsibility into his own place
    - refactoring confirmationMailMailer to reduce its responsibilities and use instead confirmationMailFactory
    - renaming confirmationMailMailer file

  2. The Open/Closed principle

    git commits done during the chapter :shipit:

    - create a genericEncoder that violates the open/closed principle
    - worsen the genericEncoder adding a case for yaml format
    - worsen the genericEncoder adding the method prepareData that also violates the open/closed principle
    - creating 3 different encoders that implements an interface, in this case I'm trusting in duck typing due the lack of interfaces in javascript language unless you use flowjs or an superset like typescript
    - creating a encodeFactory whose only responsibility is to create encoders based in the given format
    - refactoring genericEncoder to use the encoder factory
    - making encoderFactory open for extension injecting factories
    - creating another mandatory method for the encoders: prepareData
    - using prepareData of the specific encoder, however we just introduced temporal coupling...
    - removing the temporal cooupling :), who knows, maybe even it is not longer necesary the existence of genericEnconder, instead we could use the encodeFactory whenever we need it :)

  3. The Liskov substitution principle

    git commits done during the chapter :shipit:

    - adding dropbox specific implementation of fileinterface where change Owner has not implementation, this is not be a good example of a good substitute, calling that method will crash the application
    - instead of throwing exception, don't do nothing... silent behavior... we are lying to the user of our class...
    - splitting interfaces in order to avoid to need to throw an error or not make something if some user uses changeOwner in a class that not have implementation

  4. The Interface Segretation Principle

    git commits done during the chapter :shipit:

    - example of a serviceContainer that implements a interface that violates the interface segregation principle
    - separating the virtual interfaces I created, that allows one client use only what need, set, get or both :)
    - kernel code expect a service container that only need the method set
    - a example of controller that expect a service container that only need the method get
    - userRepository it is depending of a concrete class instead of a interface
    - making getUnitOfWork public to use in the new file query.js, automatically all the clients of entityManager depend of this method too, regardless if they use it, can cause backward compatibility problems...
    - adding role and header interfaces to use in entityManager

  5. The Dependency Inversion Principle

    git commits done during the chapter :shipit:

    - creating fizzbuzz function
    - making fizzBuzz open for extension, step 1
    - making fizzBuzz open for extension finished, and right now with the rules is depending on abstractions, an example of the inversion principle
    - adding authentication function that violates SRP, open close andependency inversion among others
    - making authentication depending of a concrete class of userProvider, dependency inversion still is been violated
    - authentication is not depending in connection anymore, now depends in an abstraction

  6. The Release/Reuse Rquivalence Principle

    git commits done during the chapter :shipit:

    - No commits here, a chapter with good tips :)

  7. The Common Reuse Principle

    git commits done during the chapter :shipit:

    - No commits here, a chapter with good tips :)

  8. The Common Closure Principle

    git commits done during the chapter :shipit:

    - No commits here, a chapter with good tips :)

  9. The Acyclic Dependencies Principle

    git commits done during the chapter :shipit:

    - No commits here, a chapter with good tips :)

  10. The Stable Dependencies Principle

    git commits done during the chapter :shipit:

    - No commits here, a chapter with good tips :)

  11. The Stable Abstraction Principle

    git commits done during the chapter :shipit:

    - No commits here, a chapter with good tips :)

  12. Conclusions

    git commits done during the chapter :shipit:

    - No commits here, a chapter with good tips :)

Final thoughts

I hope you enjoy the repository as much I while I was writing it ๐Ÿ˜ƒ

I strongly encourage that you should buy the book, it is really fantastic.

principles-of-package-design's People

Contributors

devcorpio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

elanhasson

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.