Skip to main content

Posts

Using Polymorphism with C# Code Examples

  Overview In this post, I have written about my favourite concept of Object-oriented programming, which is Polymorphism, even though I cannot say the word Liskov Substitution Principle because being a dyslexic person I always struggle with this word and I am no shame of saying it openly and publicly because I do not let my weakness become a barrier in my success and I always use my dyslexic not as my weakness but as my strength back to the subject of this post. Polymorphism is a fundamental concept in object-oriented programming that enables objects of different classes to be treated interchangeably. It refers to an object's ability to take on multiple forms or behaviours. In C#, polymorphism can be achieved through inheritance, interfaces, and method overloading. There are two main types of polymorphism in C#: method overloading and method overriding. Method overloading is achieved by defining multiple methods with the same name but different parameters, while method overriding ...

Using Abstraction with C# Code Examples

  Overview  In this post, I will discuss the programming concept of Abstraction. Abstraction refers to the ability to conceal implementation details while providing only the relevant information to the user. By identifying similarities among various objects and creating generalizations, Abstraction simplifies their usage. In software development, Abstraction is crucial for building intricate systems, as it reduces complexity, enhances reusability, and streamlines maintenance. I hope you find this post informative, and that I enjoyed creating it. What is Abstraction Abstraction in C# is the process of hiding implementation details while exposing only the necessary information or functionality to the user. Abstraction allows you to focus on what an object does rather than how it does it. It is one of the fundamental concepts of object-oriented programming and helps you to write code that is easier to read, understand, and maintain.   In C#, abstraction can be achieved thr...

Using Inheritance with C# Code Examples

  Overview In this article, we will explore the concept of Inheritance, which is a fundamental concept of Object-Oriented Programming (OOP) and is applicable to several programming languages including Java, C++, Python, and TypeScript. We will delve into the what, why, and how of using Inheritance and discuss the best practices for using Inheritance in C#. Additionally, we will provide code examples specifically tailored to C#. What is Inheritance Inheritance is one of the fundamental concepts of object-oriented programming (OOP) in C#. It allows a class to inherit properties and behaviour from another class, called the base class or parent class. The class that inherits from the base class is called the derived class or child class. In C#, inheritance is achieved through the use of the: symbol followed by the name of the base class. Here's an example of how to declare a derived class that inherits from a base class: In this example, the Animal class is the base class, and ...

Using Encapsulation with C# Code Example

  Overview In this article, we are looking at Encapsulation as a fundamental concept in object-oriented programming that refers to the practice of hiding the internal workings of an object from the outside world. In this article, we will explore what encapsulation is, why it is important, how to implement it in C#, and the best practices for using it effectively. It's important to note that while we will be focusing on C# in this article, the principles of encapsulation can be applied to other programming languages, including Java, Python, TypeScript, and C++. What is Encapsulation Encapsulation is one of the fundamental concepts of object-oriented programming (OOP) that emphasizes the idea of data hiding. It refers to the bundling of data and methods that manipulate the data within a single unit or class, and restrict access to the internal state of the object from the outside world.   In C#, encapsulation can be achieved using access modifiers such as public, private, prot...

JavaScript Conditional Statements

  JavaScript's Conditional Statements Overview  JavaScript's conditional statements provide the ability to execute different blocks of code depending on whether a certain condition evaluates to true or false. In this way, developers can create dynamic code that reacts to changing data or user input. Here are some examples of how to use conditional statements in JavaScript. If Statement The if statement is the most basic conditional statement in JavaScript. It allows you to execute a block of code only if a certain condition is true. Example One In the above example, I have given the code checks whether the age variable is greater than or equal to 18. If it is, the first block of code (inside the curly braces) will be executed and "You are old enough to vote." will be logged to the console. If the condition is false, the second block of code will be executed and "You are not old enough to vote yet." will be logged into the console. Example Two In the above ex...

JavaScript Operators (Arithmetic, Assignment, Comparison, Logical Conditional Ternary, Bitwise)

  JavaScript, operators are symbols or keywords used to perform operations on one or more values. JavaScript has several types of operators, which includes the following below. Arithmetic Operators Arithmetic Operators: These operators are used for basic arithmetic operations such as addition, subtraction, multiplication, and division. The addition operator + can also be used for string concatenation. Examples of arithmetic operators include +, -, *, /. Addition (+)   In this example above, I have used the addition operator is used to add two or more numbers or to concatenate two or more strings. Subtraction (-) In the example above, I have used the subtraction operator is used to subtract one number from another.   Multiplication (*)   In the example above, I used the multiplication operator is used to multiply two or more numbers.   Division (/)     In the example above, I have used the division operator is used to divide one number by another...