Skip to main content

All Questions

Filter by
Sorted by
Tagged with
0 votes
2 answers
210 views

For non-container classes, are "better naming" and "ready for commented codes" good reasons not to declare the most abstract type?

According to Why define a Java object using interface (e.g. Map) rather than implementation (HashMap), I know I should declare the most abstract type possible, but the question is about template class ...
wcminipgasker2023's user avatar
0 votes
1 answer
111 views

Should a class be an attribute for another class if all I need is the data from it?

Title sucks, I know, but I'm having trouble describing my question. Say I have a class Three_Eyed_Robot that sees the world in RGB through three eyes. Lets call them Red_Eye, Green_Eye, Blue_Eye, each ...
Ryan Folks's user avatar
2 votes
2 answers
462 views

Organization of C++ source code for reusable components

I'm implementing a custom templated container as part of a learning project in C++. The container makes use of different components like serialization, memory management, iterators. I am wondering ...
NBWL's user avatar
  • 31
3 votes
4 answers
577 views

Do "avoid primitive obsession" and "use most abstract type as possible" contradict each other?

According to Is "avoid the yo-yo problem" a valid reason to allow the "primitive obsession"?, I should define "price" like this: public class Main{ private Price price; } ...
aacceeggiikk's user avatar
1 vote
1 answer
69 views

Should I group all sound file definitions together? Or define some of them locally, if possible?

For example, suppose my application have some sound files, now I define all sound file references in a single class: public class SoundHelper{ public static Sound buttonSound=new Sound("(some url)...
ocomfd's user avatar
  • 5,750
0 votes
1 answer
1k views

Representing Java Object Hierarchy With Nested Classes

I was working with some API which was used internally, and while looking at their code I found something like this: public class Parent { @Data public static class Child { private ...
engma's user avatar
  • 111
1 vote
3 answers
331 views

How to define sound playing function? one single function for all sounds? or each sound has its own function?

After many years, I still unable to determine the correct way to define a class/function to play sound. Suppose my app may need to play some sounds, for example: button click, error popup,... How ...
ocomfd's user avatar
  • 5,750
22 votes
5 answers
3k views

How can you decompose a constructor?

Lets say I have a Enemy class, and the constructor would look something like: public Enemy(String name, float width, float height, Vector2 position, float speed, int maxHp, int ...
Travis's user avatar
  • 343
2 votes
1 answer
86 views

When should I pass setting-like value as class' variable and when as an assoc. array?

Following my other question, is there a general rule of thumb, when we should pass a setting-like value, that controls class' behavior (for example displayed texts) as as class' constant or variable, ...
trejder's user avatar
  • 2,416
1 vote
1 answer
3k views

When should I pass value as class variable and when as a method argument?

Is there a general rule of thumb, when we should pass a value as as class variable and when as a method argument? Or is it just a choice of the developer? For example -- are there any reasons, why ...
trejder's user avatar
  • 2,416
0 votes
3 answers
264 views

which style of member-access is preferable [duplicate]

the purpose of oop using classes is to encapsulate members from the outer space. i always read that accessing members should be done by methods. for example: template<typename T> class foo_1 { ...
itwasntpete's user avatar
23 votes
2 answers
5k views

Is it a good idea to provide different function signatures that do the same thing?

Here is a C++ class that gets constructed with three values. class Foo{ //Constructor Foo(std::string, int, char); private: std::string foo; char bar; int baz; }; All of the ...
Trevor Hickey's user avatar
6 votes
3 answers
2k views

How to name an subclass that add a minor, detailed thing? [closed]

What is the most concise (yet descriptive) way of naming a subclass that only add a specific minor thing to the parent? I encountered this case a lot in WPF, where sometime I have to add a small ...
Louis Rhys's user avatar
  • 6,182
9 votes
4 answers
6k views

Method flags as arguments or as member variables?

I think the title "Method flags as arguments or as member variables?" may be suboptimal, but as I'm missing any better terminology atm., here goes: I'm currently trying to get my head around the ...
Martin Ba's user avatar
  • 7,861
3 votes
2 answers
411 views

Designing class methods: self contained or explicit calls?

I'm probably butchering the terms, if someone knows the appropriate terms - that'd be great. But my question is: should I design my classes so that their methods' parameters be accessible from the ...
Itai Sagi's user avatar
  • 173