Talking about object-oriented programming
An object in the real world is a thing, such as a car or a person, whereas an object in programming often represents something in the real world, such as a product or bank account, but this can also be something more abstract.
In C#, we use the class
(mostly) or struct
(sometimes) C# keywords to define a type of object. You will learn about the difference between classes and structs in Chapter 6, Implementing Interfaces and Inheriting Classes. You can think of a type as being a blueprint or template for an object.
The concepts of object-oriented programming are briefly described here:
- Encapsulation is the combination of the data and actions that are related to an object. For example, a
BankAccount
type might have data, such asBalance
andAccountName
, as well as actions, such asDeposit
andWithdraw
. When encapsulating, you often want to control what can access those actions and the data, for example, restricting how...