Skip to main content

SOLID Software Principle Using C#

 

SOLID Software Principle Using C# by Ziggy Rafiq


SOLID Software Principle Using C#

The SOLID principle is a set of design principles for object-oriented software development that aim to make the software more maintainable, flexible, and scalable. The SOLID acronym stands for the following principles:

  • Single Responsibility Principle (SRP): A class should have only one reason to change. In other words, a class should have only one responsibility or job to do, making it easier to maintain and modify.
  •  Open-Closed Principle (OCP): Software entities (classes, modules, functions, etc.) should be open for extension but closed for modification. In other words, new features should be added by extending the existing code rather than modifying it.  
  • Liskov Substitution Principle (LSP): Subtypes should be substitutable for their base types without causing any errors or unexpected behaviour. This means that any object of a superclass should be able to be replaced by an object of a subclass without affecting the correctness of the program.
  • Interface Segregation Principle (ISP): Clients should not be forced to depend on interfaces they don't use. This means that interfaces should be designed to be as small and focused as possible, with only the methods needed by the clients that use them.
  • Dependency Inversion Principle (DIP): High-level modules should not depend on low-level modules. Instead, both should depend on abstractions. This means that the design should be structured so that modules are independent of each other, and they only rely on abstractions (interfaces), not on concrete implementations.
Overall, the SOLID principles provide guidelines for creating software that is easier to maintain, flexible, and scalable. By following these principles, software developers can create more robust and reliable software that is easier to modify and extend over time.

Comments

Most Viewed Ziggy Rafiq Blog Posts

A Complete Guide to Using GUIDs in C# with Code Examples

  Overview In this post, we are looking at GUIDs (Globally Unique Identifiers), which are widely used in C# for generating unique identifiers for objects, entities, and resources in a system. In this post, we'll explore the basics of GUIDs in C#, their advantages, and how to convert strings to GUIDs. In this post, we have used Guid Generator to create the GUID from the following URL Address https://guidgenerator.com/ What is GUID GUID (Globally Unique Identifier) in C# is a 128-bit value that is used to identify objects, entities, or resources in a unique manner across different systems and applications. It is also known as UUID (Universally Unique Identifier) in some other programming languages.   GUIDs are generated using a combination of unique factors such as the MAC address of the network adapter, the current time and date, and a random number. The resulting GUID is a string of 32 hexadecimal digits separated by hyphens, such as "b86f2096-237a-4059-8329-1bbcea72769b...

Primitives Data Types and None-Primitives Data Types in C# with Code Examples

  Overview I wrote this post to provide an explanation of primitive and non-primitive data types in C#. C# is a strongly typed programming language, where each variable and expression must have a specific data type. C# data types are categorized into two primary groups: primitive data types and non-primitive data types. Primitive data types are the simplest data types available in programming languages. They are typically pre-defined data types and can represent a single value, such as a boolean value, character, or integer. Examples of primitive data types include int, char, float, double, and boolean, which are common in programming languages like C++, C, and Java. Non-primitive data types are also referred to as composite data types or reference data types. They are constructed from primitive data types and are more complex than primitive data types. Non-primitive data types can hold multiple values and allow for the creation of more intricate data structures like tables, li...

How to Truncate String in C#

  Overview In today’s post, I am writing about one of the fundamental aspects of C# and as programmers, we should use this approach I have realised throughout my life as a software engineer that not everyone knows the most basic approaches or how to use them efficiently. Truncating a string in C# means reducing the length of a string to a specified number of characters, typically by removing characters from the end of the string. This is often done when a string is too long to be displayed or used in a specific context and needs to be shortened to fit. Ley says if we have a string that is 100 characters long, but we only want to display the first 50 characters, we will truncate the string to a length of 50. There are several ways to truncate a string in C#, including using the Substring method, StringBuilder, and LINQ. A simple example of this is below, we're creating a longString variable with a long string value. We're also defining a maxLength variable with a value of 20...