Skip to content

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

License

Notifications You must be signed in to change notification settings

devcorpio/principles-of-package-design

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published