Nerd For Tech
Published in

Nerd For Tech

Solid Principles in a Flutter

These principles are commonly used by software engineers and provide developers with several benefits.

S: The Single Responsibility Principle (SRP)

A solid principle begins with an “S”: the SINGLE RESPONSIBILITY PRINCIPLE. In the single responsibility principle, you are told that every class function method, no matter what you write, will have only one specific opportunity and should handle that responsibility exclusively. If you have a method that makes an HTTP request, the class should only know and understand how this HTTP request works, so it should only take care of the problems related to the car.

Bad Practice

Good Practice

O: The Open-Closed Principle (OCP)

In addition, there is a second big principle that starts with an “O” called the OPEN-CLOSED PRINCIPLE. This principle says that every class and method should be open for extension, but closed for modification.

Bad Practice

Good Practice

L: The Liskov Substitution Principle (LSP)

The third big principle that starts with an “L” is LISKOV SUBSTITUTION PRINCIPLE this is quite a mouthful and is also one of the hardest parts of software engineering to grasp because the principle is difficult to explain, so we’ll try to explain it a bit easier so that the list of substitution principle can be explained more easily. As I mentioned, the purpose of substitution is to replace a subtype somehow with its general parent type, so let’s say we take a coffee machine as an example.

Bad Practice

Good Practice

I: The Interface Segregation Principle (ISP)

So this brings us to our fourth principle, the fourth big principle that starts with an “I” is INTERFACE SEGREGATION PRINCIPLE which sounds a bit complicated, but is actually quite easy to comprehend. We do not want to force our clients to use an interface that contains functions or methods that they don’t use easily enough.

Bad Practice

Good Practice

D: The Dependency Inversion Principle (DIP)

Lastly, the last principle that is very important in software engineering, which starts with a “D”, is the DEPENDENCY INVERSION PRINCIPLE, which states that high-level modules must not depend on low-level modules without an abstraction. That’s a lot, but as an example, it’s quite easy to understand.

Bad Practice

Good Practice

--

--

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shirsh Shukla

Mobile Application Developer | GDG Speaker | Technical Blogger at medium | community member at StackOverflow | Organizer @FlutterIndore