From cb2241acd67808a8a7abccfa8e4c0295c762e09a Mon Sep 17 00:00:00 2001 From: yoadwo Date: Sun, 24 Mar 2019 17:01:58 +0200 Subject: [PATCH] adding "solid-principle" (#35663) * adding "solid-principle" * added title for front matter block * Update guide/english/design-patterns/solid-principle/index.md Co-Authored-By: yoadwo --- .../design-patterns/solid-principle/index.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 guide/english/design-patterns/solid-principle/index.md diff --git a/guide/english/design-patterns/solid-principle/index.md b/guide/english/design-patterns/solid-principle/index.md new file mode 100644 index 0000000000..4ec79573fd --- /dev/null +++ b/guide/english/design-patterns/solid-principle/index.md @@ -0,0 +1,28 @@ +--- +title: SOLID Principle +--- +## SOLID Principle + +A key programming princple which consists of the following conventions: +(S)ingle Responsibility Principle +(O)pen/Closed Principle +(L)iskov Substitution Principle +(I)nterface Segregation Principle +(D)ependency Inversion + +Solid Responsibilty means a class should only do one thing (and preferably, do it well). So if a class is currently +interacting with some SQL database, and also can generate a HTML page from them - the two functionalities should be seperated. + +Open/Closed Principle means you two never modify an existing class, but rather to extend them (does the word 'inheritance' ring +any bells for you?). + +Liskov Substitution is one most often ignored. It means that whenever a code is written with use of base and child classes, +it should be written as such that the program will never crash even if the child classes are substituted with their parent's. +Suppose we have an Animal base class and a Dog\Cat child classes: It should not harm the flow if we write every Dog instance with +an Animal's. + + Interface Segregation Principle means that when writing interfaces, it is better to write many ones each with very particular + purpose, rather than having one interface to rule them all. Programmers are more likely to reuse small ones, and programs will + be less cloggy with having to implement a big one. + + Dependency Inversion Principle means in (very) short, dont depend on concrete classes; try to use interfaces more.