OOP Design

How should I learn to make efficient OOP design?
I was going to make an OOP Tetris with C++ and ncurses which sounded easy but I'm struggling about designing the combination of classes, is there any book or list of exercises that helps you git gud?

Attached: 1530314307508.jpg (609x304, 110K)

Only use OOP when you need it, make a diagram of your classes, think about if you need them and where you need them. Design them as general purpose classes if you want to reuse them later. tl;dr Think and then code

Oh and the best exercise is to write code. The more you write, the more you will learn about how to make it better. Sometimes I like to rewrite my own programs over and over again to implement new things I have learned.

Yeah I'm basically looking for things to write but Tetris is the only thing that came to mind and apparently I'm too brainlet to design it in the OOP way
Some months ago I've made a rhythm game with C and ncurses so that might be a good candidate to rewrite in C++ with OOP

Was also thinking about getting a Java book since the language is all about OOP

Stick to C++. It is always a good idea to write an emulator or CHIP-8 interpreter if you are not so sure about emulators yet. I can recommend to write an emulator for the 6502.

It offers some good possibilities to use OOP. Memory management, ALU, CU, I/O etc.

Java isn't that much more OOP than sepples, honestly. You're better off learning Ruby or Smalltalk.

>How should I learn to make efficient OOP design?
Learn that it is one way to realize dynamic dispatch, which is required for some tasks.
In that regard, OOP is better than rigging some vtable together by yourself, but worse than a good implementation of multimethods.
Just realize that you shouldn't fall for the complete OOP modelling paradigm meme, as there is no money or technical merit in it.

Read "Clean Code"

>efficient OOP design
Nice oxymoron.

Try out Unreal Engine and look at how it's doing its OOP stuff. Their devs know their shit, so you can copy their style.

>efficient OOP design?
There's no such thing, that's just something pajeets say in order to get a job.

>but Tetris is the only thing that came to mind
A good practice for oop is writing a turn based ecosystem simulator.
The idea is that you have a grid on which there are symbolic representations of objects, like terrain including water, grass, plains etc,, and you have animals, herbivore, carnivore, maybe more complex food chain. And the animals have behaviors, so they can move, eat, reproduce etc. and have statistics like hunger, thirst, energy on which their behavior depends.
Everything is turn based, so after each turn plants grow, animals move, offspring is born, prey is eaten.
The point of the practice is to think of the features in your design yourself, not just copy the examples I've given above and adding them on the fly after you'll came up with new ideas, modifying your design after you've written your core features. Yes, it's a lot of code rewriting and a lot of issues and it's supposed to be like that to expose you to them.
It can be a text based console application as it will be a lot of coding already but you can make a gui or even make a webapp of it of some sort.
Then when you write the simulator you can play with it to find such initial conditions that produce a stable ecosystem. It's very hard to find then so don't be discouraged if everything dies after a few turns

So basically something like Dwarf Fortress.

>Tetris
no wonder you have issues
you're trying to squeeze oop with your knee somewhere where it's not needed

OP here, sorry I stopped replying because this seems like a pretty fking cool project so I started looking into the CHIP-8 interpreter when the post I'm replying to was written.

I did some Assembly in high school so I'm not entirely new to CPU registers and stack stuff, just started the opcode translation thing and I'm pretty thrilled, amidoingitrite??


I was thinking about Java because I'll have to start using it soon anyway but I like C and C++ so my idea was to get used to OOP with C++ while I don't need to work with Java


I'll get it

Also sounds like a fun project, thank you


Obviously OOP is not needed for Tetris but the game has... objects (the pieces, the board, the game as a whole) and it's a classic game I like so it seemed like a good candidate

Attached: Untitled.png (479x182, 15K)

>efficient
>OOP

Pick one.

>teleports an unhandled data type in your array

heh polymorphism, kid

>unhandled data type

What are __cxa_pure_virtual and __purecall?

Attached: 1510203011617.png (614x615, 552K)

OOP as a paradigm falls apart when you start shoving abstract concepts into objects. It makes sense to describe a Person object because you can imagine it as an object and what kind of information would be stored in that object. Honestly I was always stuck on designing the perfect interface between objects until I learned functional programming and realized it's all retarded. Now I just put the obvious things in objects and treat them like types and make a bunch of functions that operate on them. Put it in a namespace if you want to keep things seperate.

Tetris is much more complicated than it looks. I make a ton of games but Tetris was a real struggle. Inb4 some edgy fuck telling me that I am a brainlet and Tetris was the easiest game they ever made.

Pick something else until you are comfortable.

Attached: boomer.jpg (380x349, 35K)

What was the problem, mate?

>Tetris is much more complicated than it looks. I make a ton of games but Tetris was a real struggle. Inb4 some edgy fuck telling me that I am a brainlet and Tetris was the easiest game they ever made.
Tetris is simple as shit.
You just need to sit down and write up all the rules. And there aren't many of those.
I would know, because I wrote down a fucking pseudocode assembly version.

>pseudocode
ok

Attached: 1529852041186.png (340x314, 249K)

get these books
head first design pattern
gang of four
shits are old but still relevant because anything used in the real-world is either a dp in these books or some derivations.

You don't need OO for Tetris.
Leave that shit alone, it'll cause bad habits, use it when you need it.

Attached: photo_2018-07-01_16-52-24.jpg (1280x736, 90K)