13
votes
Supermarket Product Inventory Management with Polymorphic Product Types
First, a Code Review
Anti-pattern
Please don't do this:
record = new String();
This is (barring compiler heroics), creating a brand new empty string literal, ...
12
votes
Function overloading / dynamic dispatch for Python
I will offer some subjective opinions and objective observations.
Benefits
The main benefit of the overload pattern as I see it (including, but not exclusively, as implemented in your code) is that it ...
11
votes
Area calculator for shapes as an OOP interview test
I see some things that may help you improve your code.
Don't overcomplicate your code
The only thing required of the Shape and ...
11
votes
Accepted
A tree of polymorphic types (Crafting Interpreters Book)
Unique pointers own objects
It's important to realize that std::unique_pointer does not only free memory automatically, it also restricts copying pointers, such ...
9
votes
Adapting a hierarchy of polymorphic classes to std::variant
It won’t work
This is a bad idea, on just about every level.
Let’s start with something that can’t be argued: it just won’t work.
Your example inheritance hierarchy looks like this:
...
8
votes
Accepted
Area calculator for shapes as an OOP interview test
For a junior hire, I may have accepted the answer, but I would have pointed out the short comings while discussing the answer, and see if the candidate could adjust the code accordingly.
I agree with ...
8
votes
A tree of polymorphic types (Crafting Interpreters Book)
Enable more warnings so your compiler can help you
Many problems can be diagnosed automatically, prior to human review.
For example, using GCC:
...
8
votes
Accepted
A static version of std::polymorphic
I’m not a fan of deriving from variant for this use case, not least for the fact that it’s mixing metaphors. The point of ...
7
votes
Accepted
Implementing different types of light sources in a Graphics project
Why is LightSource inheriting from IMovable and IRotatable if not every ...
7
votes
Accepted
polymorphic message container
Overview
Your Holder class is not really useful as everything is public!
Overall, there is nothing to really review as you have not built anything. Things you ...
7
votes
Accepted
Function overloading / dynamic dispatch for Python
Does the interface seem ergonomic?;
Yes. Except having to define MyClass twice for methods. Which you may be able to solve by changing the algorithm to be lazily, ...
7
votes
Adapting a hierarchy of polymorphic classes to std::variant
You virtually never (no pun intended) want to combine std::variant with inheritance. Among other problems, most implementations of multiple inheritance will confuse ...
6
votes
Accepted
Simple implementation of signals and slots mechanism using templates
[code] uint64_t
It should be std::uint64_t, not uint64_t for key indexes (the latter is the C version). Or better: use ...
6
votes
Model animals using inheritance in Java, revised
This is better, but you are still missing a lot of basic ideas. I'm going to continue to approach the code review by looking at concepts and suggesting what you need to consider and what you should ...
5
votes
Implementing different types of light sources in a Graphics project
Overriding RotateX, RotateY and RotateZ to prevent rotation of your point light source is ...
5
votes
Accepted
Polymorphism and inheritance in C99
First of all, the obvious remark is that this needs to be split in multiple files, with a .h/.c pair for each class. Since you haven't done so, you block the possibility to make this truly OO.
It is ...
5
votes
Accepted
Maze game from book Design Patterns with smart pointers and polymorphism
You follow good practices for inheritance
The "example" you show at the beginning uses some bad practices:
It doesn't make the destructor of MapSite ...
4
votes
A vector-like polymorphic container to store objects from a type hierarchy in contiguous memory
This is some really nifty code. I'd be curious to see the full implementation and whether there were any improvements since this question was posted. :)
[code] make_aligned
Is there a reason for ...
4
votes
Accepted
Polymorphism with overrides and base calls simulating an employee
There is one thing I don't line about Employee: you are leaking memory.
Person super; should be a pointer, not the object. You ...
4
votes
Accepted
CUDA/C++ Host/Device Polymorphic Class Implementation
nice!
The code is generally rather good. I don’t have a lot to say about the language usage in the individual lines.
The idea of using an abstract base to do different implementations selected at ...
4
votes
Accepted
A C++17 std::function implementation
Nice, clean and functional.
Still, there are a few things:
If you don't have to declare a special member-function, just don't:
bad_function_call::bad_function_call()...
4
votes
Accepted
A polymorphic union in C++
I suggest not codifying the derived types suggested in the type. Only note the ultimate base, size and alignment. Thus you are open to later change.
Add a templated alias to get the proper type from ...
4
votes
Polymorphic deleter for unique_ptr
This Code Does Not Compile
I threw together some boilerplate for Integer and IntegerDeleter. The provided code appears to be ...
4
votes
Implementation of tree with different node types and faux-polymorphism in C
Remarks for beginners:
Never hide a pointer behind a typedef! Never! It makes the code confusing and very hard to read and maintain.
You can't unfortunately use a generic ...
4
votes
Accepted
Manage Excel Styles with VBA OOP Approach
Code is generally very clean, although I do have a number of reservations with some of the naming: c prefix for class modules, M ...
4
votes
Supermarket Product Inventory Management with Polymorphic Product Types
Is inheritance really the answer?
I think it's been covered that you could dynamically build your product instances, but it's not really clear to me why you'd need to. The object model feels a bit ...
4
votes
Accepted
Cache for mesh objects
I generally favor readability and maintainability over performance until profiling reveals issues.
That's a very good mindset to have. I think the lack of elegance in your code comes from the fact ...
4
votes
Adapting a hierarchy of polymorphic classes to std::variant
Create a stand-alone function instead of a type
Creating a type PolymorphicVariant is bad, as explained by indi in great detail. Davislor already hinted at not ...
3
votes
Polymorphic implementation for == with CRTP
First and foremost, I believe that your fundamental concept is flawed. Equality has a well defined meaning between objects of the same type, or between types themselves, but not in this hybrid ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
polymorphism × 125c++ × 56
object-oriented × 37
c# × 23
inheritance × 22
java × 15
beginner × 13
c++11 × 12
design-patterns × 10
interface × 10
.net × 9
c++17 × 8
python × 7
c × 7
template × 7
c++14 × 6
javascript × 5
pointers × 5
overloading × 5
python-3.x × 4
php × 4
array × 4
template-meta-programming × 4
variant-type × 4
generics × 3