Object-Oriented Programming (OOP) is a programming paradigm that relies on the concept of classes and objects. It is used to structure a software program into simple, reusable pieces of code blueprints (usually called classes), which are used to create individual instances of objects.
C# is an object-oriented programming language, which means that everything in C# is associated with classes and objects, along with their attributes and methods.
Procedural programming is about writing procedures or methods that perform operations on the data.
Object-Oriented programming, on the other hand, is about creating objects that contain both data and methods. OOP provides a clear structure for the programs and helps keep C# code DRY (Don't Repeat Yourself).
The "Don't Repeat Yourself" (DRY) principle is about reducing the repetition of code. You should extract out the codes that are common for the application, and place them at a single place and reuse them instead of repeating them.
Object-Oriented Programming has several major advantages over procedural programming:
To understand OOP, let's look at a real-life analogy.
The Fruit class has attributes like color and taste. When we create an object like Apple, it inherits these attributes from the class, but we can give it specific values (e.g., color = Red, taste = Sweet).
The Car class has properties like weight and color, and methods like Drive() and Brake(). Each specific car object will have its own weight and color, but they all share the same driving and braking behaviors defined in the Car class.
In the next few lessons, we will dive deep into the core concepts (the four pillars) of Object-Oriented Programming in C#:
Pro Tip: Grasping OOP concepts is the most important step in becoming a proficient C# developer. Take your time with the upcoming lessons!
What does the acronym DRY stand for in programming?