Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Case Analysis of object-oriented programming in C++

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "C++ object-oriented programming case Analysis". In daily operation, I believe many people have doubts about C++ object-oriented programming case analysis. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "C++ object-oriented programming case Analysis". Next, please follow the editor to study!

First, advanced object-oriented (part I)

The significance of object-oriented is that

Introduce the habitual way of thinking in daily life into programming

Intuitively map the concepts in the requirements to the solution

Building reusable software system with module as the center

Improve the maintainability and scalability of software products

Class and object are two basic concepts in object-oriented.

Class ∶ refers to a class of things, is an abstract concept

The object ∶ refers to a concrete entity that belongs to a class

A class is a model that creates different object entities.

An object entity is a concrete instance of a class model

Note: a class can have many objects, and an object must belong to a class.

Classes and objects in life

The meaning of classes and objects

Classes are used to describe abstractly the properties and behaviors unique to a class of things.

For example, the computer has CPU, memory and hard disk, and it can boot and run programs.

An object is a concrete thing that has all the attributes and behaviors described in the class to which it belongs.

Each tiger has different weight, different food intake and different temperament

II. Summary (I)

Object-oriented is an important method in software development today.

Class and object are the basic concepts in object-oriented theory.

Classes and objects come from daily life.

Each class can have multiple objects

Every object must belong to a class

Advanced object-oriented (part two)

The basic relationship between classes

Inherit

An inheritance relationship between a class subdivided from an existing class and the original class (is-a)

The inherited class (subclass) has all the properties and behaviors of the original class (parent class)

Combination

The existence of some classes must depend on other classes. This relationship is called composition.

A combined class is made up of other classes in one part.

The basic relationship between classes-inheritance

Both Hewlett-Packard and Apple inherit from computers and have all the features of computers.

The basic relationship between classes-- combination

Representation of class

Class representation-simplification

Class representation-- improvement 1

Class representation-- improvement 2

Class representation-- improvement 3

It's a bit of code, so how do you use concepts in programming to describe the properties and behavior of a class? Let's make some final improvements.

Class representation-- improvement 4

Let's write the above representation into code to see if the compiler will report an error.

# include struct Biology {bool living;}; struct Animal: Biology {bool movable; void findFood () {}}; struct Plant: Biology {bool growable;}; struct Beast: Animal {void sleep () {}}; struct Human: Animal {void sleep () {} void work () {}}; int main () {return 0;}

The following is the output:

As you can see, the compiler did not report an error, which proves that the object-oriented representation is possible.

At this point, the study of "C++ object-oriented programming case Analysis" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report