Questions tagged [trait]
The trait tag has no summary.
20 questions
4 votes
2 answers
308 views
Interface + Trait vs Abstract Class
While developing my application I faced an interesting situation: I have multiple DTO's which are almost identical in terms of methods, only properties are different. For example I have AccountDTO ...
1 vote
1 answer
237 views
C++20, specialize struct once per type and allow member functions to take type as reference, raw, std::unique|shared_ptr or any other smart ptr
Situation I have some existing functions which expect containers which can be iterated and which have certain value_type. The value_type can be a value or some (smart) pointer. All the value_type have ...
6 votes
3 answers
617 views
How to track C++ class traits?
As a fan of regular types and value semantics, I'm keen on classes becoming more regular and being non-polymorphic. As a fan of non-throwing operations, I'm keen on operations being noexcept. I also ...
12 votes
2 answers
5k views
What's the difference between a Mixin and a Trait?
From what I can tell from Scala and Hack- Mixins: Can have state (ie. instance properties) Can only provide concrete methods Can have constructors, that are called in the same order that their ...
8 votes
2 answers
753 views
Comparision of modeling with inheritance vs idiomatic trait based composition
I recently I started learning Rust and Scala and what struck me was the lack of inheritance model that I'm used to in C++ and Java. Although I can model simple things with structs and traits in Rust,...
8 votes
2 answers
7k views
Is it possible to mock and inject traits in PHPUnit?
I need to extend a third party class I cannot modify. The class's dependencies are for the most part injected through the constructor, making them easy to mock. However the class also uses methods ...
20 votes
1 answer
3k views
Why not make a language with mixin-only inheritance? [duplicate]
It seems that in all class-based or prototypal OOP languages, mixins are either an afterthought or a secondary feature. However, to me it looks like traditional inheritance is just a specific case of ...
1 vote
0 answers
514 views
When to use trait components, objects, package objects in Scala
When I am adding dependencies in Scala, I tend to use mixin trait components for those that are inherit to the class itself. For example, DaoGenerator extends Generator However, for trait components ...