Understanding the difference between OOP and FP
In this chapter, we will be discussing FP. Because most readers will be used to OOP, FP can feel rather alien to them to begin with.
So, in this section, we will cover an example written first as an OOP program, and secondly as a FP program.
Let’s consider a simple example where we model a basic shape, such as a rectangle, using both OOP and FP approaches. We will start with the OOP code first:
class Rectangle{ public double Length { get; set; } public double Width { get; set; } // Constructor public Rectangle(double length, double width) { Length = length; Width = width; } public double CalculateArea() { ...