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

What is the difference between using classes to represent interfaces and implementations in C++

2025-01-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail what is the difference between the interface and implementation of classes in C++. The content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

C: use classes to show the difference between interfaces and implementations

Reason (reason)

A clear distinction between interfaces and implementations can improve readability and simplify maintenance.

Example (sample)

Class Date {public: Date (); / / validate that {yy, mm, dd} is a valid date and initialize Date (int yy, Month mm, char dd)

Int day () const; Month month () const; / /... private: / /. Some representation...

}

For example, in the above code, we can modify the implementation of Data without affecting the consumer (although it may need to be recompiled).

Translator's note: this example should not provide complete code, so the author's idea is not fully expressed. The code for Data should follow the following principle: the public part is only used to declare the interface of Data, while the private part is used for the specific implementation of Data, including private member functions. The access rights of members are determined based on whether they are interfaces or implementations, rather than others. Note (Note)

This is certainly not the only way to use classes to show the difference between interfaces and implementations. For example, we can use a separate set of functions in a namespace, an abstract base class, or a template function that represents an interface that contains concept parameters. The most important thing is to make a clear distinction between the interface and the concrete implementation. Ideally, and generally, the interface will be more stable than the implementation.

Concept is a new feature introduced by C++.

On C++ in the use of classes to show the difference between the interface and implementation is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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: 297

*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

Internet Technology

Wechat

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

12
Report