- Hands-On Object:Oriented Programming with C#
- Raihan Taher
- 304字
- 2021-07-02 12:44:40
Classes in OOP
In OOP, you derive objects from classes. In this section, we'll take a closer look at what a class actually is.
Classes are one of the most important concepts in OOP. You can say they are the building blocks of OOP. A class can be described as the blueprint of an object.
A class is like a template or blueprint that tells us what properties and behaviors an instance of this class will have. In most circumstances, a class itself can't actually do anything—it is just used to create objects. Let's look at an example to demonstrate what I am saying. Let's say we have a Human class. Here, when we say Human, we don't mean any particular person, but we are referring to a human being in general. A human that has two hands, two legs, and a mouth, and which can also walk, talk, eat, and think. These properties and their behaviors are applicable to most human beings. I know that this is not the case for disabled people, but for now, we will assume our generic human is able—bodied, keeping our example simple. So when we see the aforementioned properties and behaviors in an object, we can easily categorize that object as a human object or person. This classification is called a class in OOP.
Let's take a closer look at the properties and behaviors of a Human class. There are hundreds of properties that you can list for a human, but for the sake of simplicity, we can say that the following are the properties of a human being:
- Height
- Weight
- Age
We can do the same for behavioral properties. There are hundreds of particular behaviors that a person can perform, but here we will only consider the following:
- Walk
- Talk
- Eat
- 深入核心的敏捷開發:ThoughtWorks五大關鍵實踐
- 玩轉Scratch少兒趣味編程
- Photoshop智能手機APP UI設計之道
- Flask Web開發入門、進階與實戰
- 深入理解Java7:核心技術與最佳實踐
- INSTANT CakePHP Starter
- Learn WebAssembly
- Scala謎題
- Java項目實戰精編
- HTML+CSS+JavaScript網頁設計從入門到精通 (清華社"視頻大講堂"大系·網絡開發視頻大講堂)
- 大學計算機基礎實訓教程
- Python Digital Forensics Cookbook
- C語言程序設計與應用實驗指導書(第2版)
- C語言程序設計教程
- Java編程指南:語法基礎、面向對象、函數式編程與項目實戰