Back to Basics: Designing Classes (part 1 of 2)Back to Basics Designing Classes (part 1 of 2) Klaus Iglberger, CppCon 2021 klaus.iglberger@gmx.de2 Klaus Iglberger C++ Trainer/Consultant Author of the C++ math library (Co-)Organizer Beck, TDD by Example)The Challenge of Class Design 10 Guideline: Design classes for easy change. Guideline: Design classes for easy extensions.Design Guidelines 11 Back to Basics: Class Design (Part ) const; 23 Using inheritance naively to solve our problem easily leads to … … many derived classes; … ridiculous class names; … deep inheritance hierarchies; … duplication between similar implementations0 码力 | 87 页 | 5.64 MB | 6 月前3
Back to Basics: Designing Classes (part 2 of 2)Back to Basics Designing Classes (part 1 of 2) Klaus Iglberger, CppCon 2021 klaus.iglberger@gmx.de2 Klaus Iglberger C++ Trainer/Consultant Author of the C++ math library (Co-)Organizer duplication to enable you to change everything in one place (the DRY principle). Guideline: Design classes for easy change.Data Member Initialization 24 struct Widget { Widget() : Widget(42) // Decisions 63 Guideline: Encapsulate design decisions (i.e. variation points). Guideline: Design classes for easy change.Qualified/Modified Member Data 64 Back to Basics: Class Design (Part 1) The Challenge0 码力 | 76 页 | 2.60 MB | 6 月前3
Class LayoutConsulting, Inc. www.stevedewhurst.com 1 Copyright © 2020 by Stephen C. Dewhurst and Daniel Saks C++ Classes Only non-static data declarations in a class definition add anything to the size of class objects duration. Therefore, we won’t be discussing static data members. Type member (included nested classes) do not affect class layout. Non-virtual member functions have no effect on class layout. However Space… An empty class has no non-static data members, no virtual functions, and no virtual base classes. We often call these types/objects/closures “stateless.” However, even an empty class must occupy0 码力 | 51 页 | 461.37 KB | 6 月前3
Dependency Injection in C++linked in with all of the real dependencies • One for Testing • Simple implementation of some Test classes / functions • Alternate implementation files(.cpp) live in an alternate/test code branch • One link Dependency Injection Dependency Injection roadblocks : • Objects full creation hidden inside functions/classes ❑ No handle to inject new functionality ❑ Default class constructors initialized via Singletons/GlobalsBloomberg functions/classes ❑ No handle to inject new functionality ❑ Default class constructors initialized via Singletons/Globals • Reaching through multiple objects ❑ Long chains of mock classes needed as0 码力 | 106 页 | 1.76 MB | 6 月前3
COMPOSABLE C++log_sink classes: classes:CASE STUDY: LOGGING CASE STUDY: LOGGING Given the Given the push push function, we can write various function, we can write various log_sink log_sink classes: classes: "ordinary" push push function, we can write various function, we can write various log_sink log_sink classes: classes: "ordinary" sinks that send entries to di�erent places (�le, output window, etc) a �lter sink push push function, we can write various function, we can write various log_sink log_sink classes: classes: "ordinary" sinks that send entries to di�erent places (�le, output window, etc) a �lter sink0 码力 | 124 页 | 8.28 MB | 6 月前3
《深入浅出MFC》2/e觉,欣喜自己能在迷时找到良师。 武汉"wking"Microsoft Developer Studio 与MFC(Microsoft Foundation Classes)相配合,构成了一个强大 的利用C++ 进行32 位Windows 程序开发的工具,但是由于MFC 系统相当庞大,内 容繁杂,并且夹杂着大量令初学者莫明其妙的macros,更加大了学习上的难度。 框架编程? 侯俊杰回复:的确如此。MFC 其实就是把Windows API 做了一层薄薄包装,包装于各个设 计良好的classes 而已。所以,掌握了MFC framework 架构组织之后,接下来在programming 实务方面,就是去了解并运用各个classes,而各个classes 的member functions 有许多就是 Windows APIs 的一对一化身。 xvii 左营luke@orchid Handling) / 096 Template / 100 Template Functions / 101 Template Classes / 104 Templates 的編譯與聯結 / 106 第3章 MFC 六大關鍵技術之模擬 / 109 MFC 類別階層 / 111 0 码力 | 1009 页 | 11.08 MB | 1 年前3
Just-In-Time Compilation: The Next Big Thing[FUTURE] AST INJECTION (META/REFLECTION)? [NEARER FUTURE?] TEMPLATES IN LOCAL CLASSES [NEARER FUTURE?] TEMPLATES IN LOCAL CLASSES 6 . 20WORKING AROUND LIMITATIONS WORKING AROUND LIMITATIONS PRECOMPILED HEADERS [NEARER FUTURE?] TEMPLATES IN LOCAL CLASSES [NEARER FUTURE?] TEMPLATES IN LOCAL CLASSES P1988 ALLOW TEMPLATES IN LOCAL CLASSES P1988 ALLOW TEMPLATES IN LOCAL CLASSES 6 . 20WORKING AROUND LIMITATIONS WORKING TEMPLATES IN LOCAL CLASSES [NEARER FUTURE?] TEMPLATES IN LOCAL CLASSES P1988 ALLOW TEMPLATES IN LOCAL CLASSES P1988 ALLOW TEMPLATES IN LOCAL CLASSES P2044 MEMBER TEMPLATES FOR LOCAL CLASSES P2044 MEMBER TEMPLATES0 码力 | 222 页 | 5.45 MB | 6 月前3
Object Oriented Programmingreferences can destroy instances of derived classes. ▪ protected and non-virtual: ▪ Base class pointers or references cannot destroy instances of derived classes. Destructors should not fail; make them organized concepts. Base classes typically act as interfaces. ▪ Interface inheritance uses public inheritance. It separates users from implementations to allow derived classes to be added and changed users of base classes. ▪ Implementation inheritance often uses private inheritance. Typically, the derived class provides its functionality by adapting functionality from base classes.Implementation0 码力 | 38 页 | 752.99 KB | 6 月前3
Delivering safe C++resources • No elaborate run-time support (e.g., no GC) • Manage complexity – based on Simula • Classes • Strong static type checking Stroustrup - C++ safety -CppCon - October 2023 15 I needed a tool C in 1979 aka “Classic C” double sqrt(); double x = sqrt(2); /* crash */ • C with classes in 1980 (C and C++ today) double sqrt(double); // argument type required double x = sqrt(2); conservativeKey idea: “Represent concepts in code” • Direct representation of ideas in code • Focus on classes • Make code more declarative • Make more information available to compilers • Early examples •0 码力 | 74 页 | 2.72 MB | 6 月前3
Back to Basics: Object-Oriented Programminghttps://AndreasFertig.com post@AndreasFertig.com 3Training services ■ I’m available for inhouse classes, onsite or remote. ■ You can also book my course at the CppCon Academy. ■ Or one of my fellow instructors post@AndreasFertig.com 5A class ■ C++ adds classes for object-oriented programming. ■ The constructors B are called when the object is cre- ated. ■ Data fields of classes should be initialized in the constructor initialization list C . ■ The body of the constructor D is available for further opera- tions. ■ Classes can consist of member functions E and data fields G with different access rights A . ■ For everyone:0 码力 | 20 页 | 1.04 MB | 6 月前3
共 172 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18













