Chapter 3. Object-Oriented Programming in C#

This chapter will introduce you to the foundation of C# and object-oriented programming (OOP). In this chapter, you will cover the following recipes:

  • Using inheritance in C#
  • Using abstraction
  • Leveraging encapsulation
  • Implementing polymorphism
  • Single responsibility principle
  • Open/closed principle

Introduction

During your career as a creator of software, you will hear the term OOP many times. This design philosophy allows for objects to exist independently and can be reused by different sections of code. This is all made possible by what we refer to as the four pillars of OOP, namely inheritance, encapsulation, abstraction, and polymorphism.

In order to grasp this, you need to start thinking of objects (which are basically instantiated classes) that perform a specific task. Classes need to adhere to the SOLID design principle. This principle is explained here:

  • Single responsibility principle (SRP)
  • Open/closed principle
  • Liskov substitution principle (LSP)
  • Interface segregation principle
  • Dependency inversion principle

Let's start off with an explanation of the four pillars of OOP, after which we will have a look at the SOLID principle in more detail.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.217.220