Тёмный

The Factory Pattern - Mike Shah - CppCon 2021 

CppCon
Подписаться 149 тыс.
Просмотров 19 тыс.
50% 1

cppcon.org/
github.com/CppCon/CppCon2021
---
C++ programs that are dynamic in nature have to create objects at some time during run-time. New objects can be created by explicitly calling ‘new’ and then the data type of that object. However, this requires that a programmer knows at ‘compile-time’ what object should be created. What we would like, is to have a layer of abstraction, or someway to create objects at run-time to reflect the dynamic nature of some C++ programs. Luckily, there is a common pattern that can help solve this problem--the factory design pattern.
In this talk, we are going to discuss a creational design pattern known as a factory. The pattern can be as simple as a function, or take on other forms as a distributed factory, or an abstract factory. We’ll show some basic examples of a factory in modern C++ as well as real world use cases of where factories occur for further study. Finally, we’ll discuss the tradeoffs of the factory pattern, and discuss which scenarios you may not actually want to use a factory. Attendees will leave this talk with the knowledge to go forward and implement the factory pattern, as well as how to spot the factory pattern in projects they may already be working on!
---
Mike Shah
Michael D. Shah completed his Ph.D. at Tufts University in the Redline Research Group in 2017. His Ph.D. thesis advisor was Samuel Z. Guyer. Michael finished his Masters degree in Computer Science in 2013 at Tufts University and Bachelors in Computers Science Engineering at The Ohio State University in 2011. Currently Michael is a lecturer at Northeastern University.
Michael discovered computer science at the age of 13 when googling ”how do I make games”. From that google search, Mike has worked as a freelance game developer, worked in industry for Intel, Sony Playstation, Oblong Industries, and researched at The Ohio Supercomputer Center to name a few. Mike cares about building tools to help programmers monitor and improve the performance of realtime applications- especially games.
In Michael’s spare time he is a long distance runner, weight lifter, and amateur pizza maker.
---
Videos Filmed & Edited by Bash Films: www.BashFilms.com
RU-vid Channel Managed by Digital Medium Ltd events.digital-medium.co.uk
*--*

Наука

Опубликовано:

 

19 фев 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 16   
@MikeShah
@MikeShah 2 года назад
Thanks for having me CppCon! I hope folks enjoy this pattern! :)
@superscatboy
@superscatboy 2 года назад
Thanks for the great talks, Mike! You're an asset to the back to basics track.
@janoskiss5335
@janoskiss5335 2 года назад
When I learnt about Factory Pattern the first thing came in my mind what Command and Conquer:) Awesome job Mate 👏
@Hamid1Reza
@Hamid1Reza 2 года назад
A great approach for mimicking somehow a virtual constructor in the abstract class and allowing for the run time object creation. I think using modern features of c++ like std::function, lamda, code injection (or the old feature, macro), we can make it more general. So that we can auto generate the required static members and methods. We also can generat various constructor intrefaces for the object.
@newoap
@newoap 2 года назад
Really enjoyed the talk Mike. You should do the State design pattern next as that is one I have trouble understanding😉
@ChopinDolphy
@ChopinDolphy 7 месяцев назад
Mike is a fantastic educator and I think if this talk was just in the back to basics track, and not the software design track, there would have been a lot less annoying nitpicky comments/“questions” from professionals with their egos hurt by being taught something they already know.
@Hav0c1000
@Hav0c1000 2 года назад
I tried to extend your fancy registration style factory pattern. I wanted just two things: 1. Don’t force the concrete create method to obey a fixed constructor function signature (use variadic template). 2. Use std::function… I flamed out miserably, perhaps because I was running on 5 hours of sleep and 3 cups of coffee…
@yunlongliu9726
@yunlongliu9726 2 года назад
Great talk. Really appreciated. But seems more like a lecture instead of a conference talk. Maybe CppCon should consider some categorical or tag system on two aspects: 1. level of expertise. 2. the content category like design pattern, data structures, meta, etc. 2 might be obvious given its name. 1 should really has a tag associated so that everyone can get what he wants.
@qm3ster
@qm3ster 2 года назад
My gripe is not with running interspersed updates and renders (which you admit is a problem) but with keeping all game objects as `Rc`. Wouldn't keeping objects of the same concrete type in individual dense non-dynamic collections (whether all together like in your prototype or split into Components within Systems) rather than a single collection of heterogenous dynamic objects always win?
@nabeelsherazi8860
@nabeelsherazi8860 2 года назад
Is there any way in C++ to write this code using a generic like you might in C#? Like instead of Factory::Create(“ant”, 5, 5) could you do Factory::Create(5, 5) ?
@SkraxsChannel
@SkraxsChannel 2 года назад
template void MakeItComplicated(T* any) { any->compilcated = Factory::CreateComplicated(5,5); } Can also be done using concepts, if you want to be fancy. Or just .. Ant ant; ant.complicated = Factory::CreateCompilcated(5,5);
@bryanlozano8905
@bryanlozano8905 2 года назад
Why was the singleton create method required? Wouldn't it be likely that one would create more than one instance of ant?
@__hannibaal__
@__hannibaal__ 7 месяцев назад
I try with lambda is working well, better make it whole class as templates with function type or something like that.
@childhood1888
@childhood1888 2 года назад
41:47
@qm3ster
@qm3ster 2 года назад
Inheritance bad REEEEE
@nextlifeonearth
@nextlifeonearth 2 года назад
I honestly don't think this is a good example of a use case for the factory pattern. In games you're more likely to use(and you should probably use) an ecs. In what case it can be useful in in games is in combination with a state pattern. That's pretty much the only instance where we use factories in our real-time applications.
Далее
Back to Basics: Classic STL - Bob Steagall - CppCon 2021
1:01:31
Incredible magic 🤯✨
00:53
Просмотров 5 млн
Неожиданно?
00:25
Просмотров 83 тыс.
Back to Basics: Concurrency - Mike Shah - CppCon 2021
1:02:07
10 Design Patterns Explained in 10 Minutes
11:04
Просмотров 2,2 млн
Branchless Programming in C++ - Fedor Pikus - CppCon 2021
1:03:57
Это спасёт камеру iPhone
0:32
Просмотров 459 тыс.