Principle of Software Engineering

Principle of Software Engineering

Software engineering or software engineering principles is a guideline used in making designs on software. These principles ensure that the resulting software is structured, easy to understand, and modified.

Here are examples of software engineering principles:

1. KISS (Keep It Simple, Stupid)

Ok, let's start with the simplest principle: KISS (Keep It Simple, Stupid / Keep It Stupid Simple / Keep It Simple, Silly / Keep It Simple and Straightforward Keep It Small and Simple).

From the name, we must have guessed what it meant. Yup, this principle teaches us not to think too complex for simple problems. Use simple solutions to simple problems. Example: We don't need to use a microservices architecture for simple landing page needs.

Another example in code:

  • NOT – KISS WAY

  • KISS WAY


2. DRY (Don’t Repeat Yourself)

Don't Repeat Yourself. Don't create the same code over and over again in different places. This will make the code difficult to maintain. Simply create one function in one place and then call/use the function repeatedly. DRY also applies at a higher level, for example in classes and packages. Don't create a class with the same function if there are already other classes. Use that class or inherit if modifications are needed.

The opposite of the DRY principle is WET (Write Everything Twice). With WET, the same code is written over and over again.

Example Implementation:

  • NOT DRY ~ WET

DRY


3. YAGNI (You Aren’t Gonna Need It)

You Ain't (Aren't) going to Need It = You won't need it.

This principle teaches us to write code only what is needed, not to think too long so that we include functions that we will not need. For example, as a programmer, we are asked to create a prototype of an online store application. We think we will make it with Flutter technology for the mobile app, the backend with Spring Boot with a microservices architecture. The DB uses MongoDB and Redis as its cache. But it turns out that after we create it, our product manager only captures the view to be displayed on the presentation slides.

YAGNI is in line with KISS, which is that we should not think too far and complex. Thinking ahead is good, but there must be a limit. Because in working on a project there are limits that we must follow, for example timeline, budget, etc.


4. SOLID

SOLID Principles are one of the "standard" principles that can be applied to the program code we create. If we apply the SOLID principle, then the code we create will be much better; Easier to maintain, flexible, reusable, extendable. In other words, our code becomes more "pro".

SOLID was popularized by Uncle Bob (Robert C. Martin), although some of the items in it have been popularized before by others. Uncle Bob is the author of the book "Clean Code: A Handbook of Agile Software Craftsmanship". This is one of the books that I recommend to every programmer to read.

"Writing clean code is what you must do in order to call yourself a professional. There is no reasonable excuse for doing anything less than your best." Robert C. Martin

1. SRP (Single Responsibility Principle)

Definition: "A class should have one and only one reason to change (single responsibility)" In a class, only one responsibility can be filled. Don't put a variety of code into a single class. Example: If the class is responsible for managing the "users" table, then it should not be overloaded with the "orders" table for example, or by adding a year-end discount calculation. Discount calculations should be separated into separate classes. The management of the "orders" table must also be separated into separate classes.

Why is this important?

  • When writing a class or function dedicated to a single function, it is easier to understand, maintain, and modify your code.
  • If you want to change the functionality of the system, it will be easy to find the parts of the code that need to be changed.
  • Make the code more organized and easy to read. It also makes code reuse easier.

Implementation Examples:

  • No SRP

  • With SRP


2. OCP (Open Closed Principle)

Definition: "Entities (classes, modules, functions etc.) should be open for extension but closed for modifications".

The class/function must be extendable without changing the code in it. Hmm sounds tricky, but in programming it can be done.

This idea is facilitated by the Open/Closed Principle. Our functions, classes, and modules should be designed in such a way that they are open to expansion, yet closed to modification.

  • Open for Extension: New functions can be added to classes and modules without breaking existing code. Composition and heritage can be used to achieve this.
  • Closed for Modification: We recommend that you don't make changes that break the current functionality, as this requires refactoring from existing code and writing some tests to make sure the changes work.

Example Implementation:


3. LSP (Liskov Substitution Principle)

Dedefinition: "Functions that use pointers or references to base classes must be able to use objects of derived classes without knowing it". Classes must be switchable with their child classes without causing logical or technical errors.

Example of Implementation:


4. ISP (Interface Segregation Principle)

Clients should not be forced to depend upon interfaces that they do not use."

The interface is created according to the client's needs, and should not force the implementation of all functions. Because, maybe some functions are not needed by the class.

Example:


5. DIP (Dependency Inversion/Injention Principle)

Definition: "Clients should not be forced to depend upon interfaces that they do not use." A. "High level modules should not depend upon low level modules. both should depend upon abstractions." B. "Abstractions should not depend upon details. Details should depend upon abstractions."

Similar to SRP, but this applies to the interface. Interfaces should also not have too many functions that force the client class to implement all the functions. Because, maybe some functions are not needed by the class.

If this kind of information is useful, don't forget to follow along us to keep getting the latest updates about the development of the world of Technology and Information.

Berita Rekomendasi

Mengenal Bahsa Pemprograman Psycript

12/11/2024

Getting to Know Psycript Programming

PyScript adalah sebuah terobosan yang memungkinkan script Python dijalankan langsung di dalam browser. Teknologi ini menggabungkan sintaks Python dengan elemen HTML standar, sehingga memberikan fleksibilitas dalam pengembangan aplikasi berbasis web.…

View
GraphQL vs REST API Apa Bedanya?

11/11/2024

Here are some tips that we can share, if this information is useful don't forget to keep following

 API atau Application Programming Interface adalah sebuah protokol atau teknologi yang digunakan menangani sebuah perangkat lunak berinteraksi satu sama lain. Salah satu contohnya adalah untuk mendapatkan data dari database.      GraphQL API menyediakan kemudahan dalam…

View
Optimalkan Ketersediaan Aplikasi LoadBalancer

25/09/2024

Optimize LoadBalancer Application Availability

High Availability (HA) adalah kunci untuk menjaga aplikasi dan database tetap tersedia saat terjadi kegagalan sistem atau lonjakan beban. Untuk itu, penggunaan Aplikasi Load Balancer (LB) sangat penting dalam arsitektur…

View