Back to Basics: Designing Classes (part 1 of 2) - Klaus Iglberger - CppCon 2021

preview_player
Показать описание
---
Designing good, maintainable classes is a challenge. Sometimes it even feels like there is a decision to make in every single line of code. This talk will help you master this challenge. It will explain …

* … why small classes are beautiful;
* … why it is so important to encapsulate variation points;
* … why inheritance is rarely the answer for customization;
* … how to write good and maintainable constructors;
* … how to make sure class invariants are maintained;
* … how to handle member data;
* … how to write good member functions;
* … how to write good supporting functions;
* … why your private members are not private at all.

---
Klaus Iglberger

---

*--*
Рекомендации по теме
Комментарии
Автор

one of the worlds greatest speakers on c++. No idea we he hasn't published a book, or even recorded his workshops.

omid_tau
Автор

This is just pure gold! I wish I could find more similar quality talks. Not sure if any other good ones, there are so many talks uploaded recently, which overwhelm my digestion.

lehaipham
Автор

Great presentation. To the point with clear examples . Klaus doesn't disappoint.

MyMjrox
Автор

Klaus talks are always very qualitatively dense and great. Back to basics or not, always useful.

simonfarre
Автор

Another great talk from Klaus. Always look forward to his Back to Basics talks

mehtubbhai
Автор

Everyone needs a refresher now and then :) This one held me captivated for the entire duration.

iamjadedhobo
Автор

29:10: I really like the idea of providing the DrawStrategy by means of a template argument to the class. Unfortunately, the slide does not show how one would instantiate such a class. I managed to do this via a functor that I give as the template argument. However, is it also possible via a Lambda or via std::function? Would be very grateful if someone could explain how to do that.

thodin
Автор

Excellent presentation, congratulations to the presenter and a big thanks to CppCon for sharing..

sotirissalloumis
Автор

Designing classes is a constant search for orthogonalities.
Exple:
Circle->(implements)->the shape interface.
Circle::draw -> calls RenderEngine::draw.
Circle::draw generates the vertices of a circle, RenderEngine::draw uses whatever drawing engine (opengl, vulkan, Dx..etc) to lay these vertices on a color buffer.
Instantiating a Circle by giving it a derived class of "DrawXXXXstrategy" means the user have to know which concrete class he has to use to render his circle. However this information is only relevant to the render engine, it is the one and only object which should know about the underlying platform.
As an implementer of circle::draw method, i have only to say:
void circle::draw(radius, resolution)
{
vector<vertex> circumference;
for(int i=0; i<360; i+=resolution) {circumference.push_back(math_VertexOnCircleAtAngle(i, radius));}

}

That's how it should be implemented.
The Circle::draw, draws mathematically the circle,
The RenderEngine::draw, draws physically the circle.
I don't even need to guess if i should use OpenGl or Vulkan or whatever. The RenderEngine will figure it out for me.
On top of that, the RenderEngine instance is usually the same for the whole program since it is related to the platform you are rendering on.

Every time I'm faced to designing classes, i always face the problem of "to what extent i have to breakdown my classes responsibilities ".
It is a tough process, but experience will teach you a lot.

dadisuperman
Автор

Excellent talk Klaus. Definitely its one of the best back to basic on design class. Am a big fun of you.

learntolearn
Автор

Really enjoying this series.
Klaus Iglberger is an excellent presenter.

Looking forward to more Back to Basics videos.

CostaKazistov
Автор

Good talk. Enjoyed his training in my uni.

maneshipocrates
Автор

I would prefer Length to Size for the second array template parameter. Size is too easily confused with the size in memory, and in some ways (e.g., sizeof) could be more confusing than just N.

sirhenrystalwart
Автор

Thank you soo much for these valuable lessons! Code examples made it very clear to me.

jmbrjmbr
Автор

13:29 Can anyone tell me what font is that (for the class definition) ? Its gorgeous!

nandanvasudevan
Автор

Excellent, you explain things very well, practical and to the point.

antonfernando
Автор

"#define private public", at least at one point, didn't work with Microsoft compilers because they included the access region in the name mangling.

jimfcarroll
Автор

At last a talk about the important first principles upon which much of the specialized material can be designed and built.

paulchamberlain
Автор

At 43:34 he says that by making the test class a friend you couple it into the production code. Can someone elaborate?

georgesimeonidis
Автор

Very Informative talk on design decisions !!!

vishnuuppada