Skip to main content
Share Your Experience: Take the 2024 Developer Survey
42 votes

Why use a special "Name" class (instead of just a string) for representing object names in C++?

from everything I've seen, the Name class has no purpose besides providing a mutex, various asserts and other runtime error checking This is the reason why — it has behavior associated with it, which ...
Greg Burghardt's user avatar
33 votes

In OOP, what counts as a "getter"

So what exactly is a "leaky abstraction" via getters ? Emphasis on exactly. What is exposing data exactly ? If you're looking for exact deterministic discussion of big picture software ...
Flater's user avatar
  • 51.7k
24 votes

How far can you push Object Oriented Programming?

I think the principle that all getters somehow violate oop principles at some fundamental level is wrong. If I have a string class and I want to know how long the string is by calling getLength does ...
chubbsondubs's user avatar
17 votes

How far can you push Object Oriented Programming?

This is not a getter Just because a method has get in its name doesn't mean it's a getter; nor does renaming a getter to eg say fetchName stops it from being a getter. In fact, the getItem method is ...
falsedot's user avatar
  • 295
17 votes

Why use a special "Name" class (instead of just a string) for representing object names in C++?

from everything I've seen, the Name class has no purpose besides [a list of various purposes] Sorry if this comes across as facetious but you rolled from claiming there's no purpose into listing the ...
Flater's user avatar
  • 51.7k
12 votes

Why use a special "Name" class (instead of just a string) for representing object names in C++?

the Name class has no purpose besides providing (...) These are good reasons to introduce a seperate class, but even if Name wouldn't have any additional behaviour it is still beneficial to have a ...
freakish's user avatar
  • 973
10 votes

How far can you push Object Oriented Programming?

I'll take a stab at it but I'll just touch on the hash table question. Firstly, the person that replied to you, is an advocate of Object oriented domain driven development (coined by him) and ...
Ced's user avatar
  • 589
9 votes
Accepted

How far can you push Object Oriented Programming?

However, some boundaries, like library boundaries, make it impossible to move the method and so you move data. I agree. Sometimes you do not (or can not) know the behavior that will be attached to ...
Robert Bräutigam's user avatar
9 votes

In OOP, what counts as a "getter"

A "getter", for the purposes above of talking about code maintainability and design, is any method that returns an object that already existed when the call began, that the caller didn't ...
Robert Bräutigam's user avatar
7 votes

Why use a special "Name" class (instead of just a string) for representing object names in C++?

@Flater correctly identified the Primitive Obsession issue, but it may be warranted to explain a bit more why primitive obsession is an issue. What's in a type? Types are used for a variety of ...
Matthieu M.'s user avatar
7 votes
Accepted

Refactoring Processor classes

If you are sure that you are violating the SRP, what actual problems does that cause you? Years ago someone analysed common problems and found root causes. With the SRP, the problem is not that a ...
gnasher729's user avatar
  • 45.7k
6 votes

In OOP, what counts as a "getter"

A getter is a failure to design an object. It violates encapsulation which is a core principle of object oriented programing. Now please tell me, how do you design a libraries hash table collection ...
candied_orange's user avatar
6 votes

Do private members/methods inherently violate the open-closed principle?

For inheritance to work well you need to design your base class with inheritance in mind. In that case you should carefully consider what properties and methods should be protected or private, as well ...
JonasH's user avatar
  • 5,544
5 votes

How far can you push Object Oriented Programming?

You can't infer OOP from a line of code This question is a bit of a semantic puzzle in what it's asking. But that not every line of a program can be purely object oriented. Yeah, because object ...
Flater's user avatar
  • 51.7k
5 votes
Accepted

What is a good architecture / design pattern for giving multiple shared attributes in different combinations?

Yes there is. It is called the entity component system. It is used mostly in gaming industry to avoid deep hierarchies and share "components" (attributes or behavior or both) between "...
Christophe's user avatar
  • 77.9k
4 votes

In OOP, what counts as a "getter"

A getter is a function that returns a value (usually one that's stored in an object's member variable). A setter is a function that takes a value as a parameter and uses it to modify an object's state....
dan04's user avatar
  • 3,949
4 votes
Accepted

Do private members/methods inherently violate the open-closed principle?

Thought experiment: imagine a component designed to be OCP-compliant, with certain extension points and public members, so it can be reused in a black-box fashion in several use cases. Imagine also ...
Doc Brown's user avatar
  • 208k
3 votes

In OOP, what counts as a "getter"

I'm late to the party but going to throw this anyway since its ended up a massive discussion. There is no definition of a "getter" because its not what it does, but how you use it that's the ...
Ewan's user avatar
  • 76.3k
2 votes

Why use a special "Name" class (instead of just a string) for representing object names in C++?

Given the description, it appears the code base isn't just (merely) to enable loading/saving as XML; it appears to me that it's designed to faithfully recreate an in-memory representation of the ...
rwong's user avatar
  • 16.9k
2 votes

Why use a special "Name" class (instead of just a string) for representing object names in C++?

If you have a “Name” class instead of string, you can use it to split into family name and given name, salutation, ordering (that’s why I didn’t say “first name” because for some people the family ...
gnasher729's user avatar
  • 45.7k
2 votes

What is a good architecture / design pattern for giving multiple shared attributes in different combinations?

The basic approach for specifying arbitrary data fields arranged in arbitrary shapes, and for implementing algorithms which perform processing upon those fields and shapes, is nowadays called "...
Steve's user avatar
  • 8,949
2 votes

In OOP, what counts as a "getter"

So what exactly is a "leaky abstraction" via getters For added emphasis, let's change your Account code to final String _email; String get email => _email; This leaks the information ...
user949300's user avatar
  • 8,849
2 votes

How far can you push Object Oriented Programming?

Does this count as a "pure" HashTable? Note that any data container, like an array or hash table, can expose a ForEach method that takes a function pointer as argument and call that function ...
Ccm's user avatar
  • 1,589
2 votes

How far can you push Object Oriented Programming?

I almost responded with an answer similar to this on the other question and decided not to. I've been tempted twice, I'll bite. What are we even arguing about here? Why do we do Object Oriented ...
Jared Smith's user avatar
  • 1,925
1 vote

Do private members/methods inherently violate the open-closed principle?

Private methods does not in themselves violate the open-closed principle, but a class with only private methods would violate the principle because such a class is not extensible. Your problem with ...
JacquesB's user avatar
  • 59.7k
1 vote

Do private members/methods inherently violate the open-closed principle?

When I make a method private, it means “it’s not designed to be reusable. If you want to reuse it, do it at your own risk and don’t come crying to me if it doesn’t work”. Open/closed principle doesn’t ...
gnasher729's user avatar
  • 45.7k
1 vote

How far can you push Object Oriented Programming?

The actual question you are asking is: "How far can you push the "Tell, don't ask"-principle." The answer is, you should push it as long as it improves encapsulation, but you can ...
JacquesB's user avatar
  • 59.7k
1 vote

How far can you push Object Oriented Programming?

My view is that OOP primarily exists to permit decentralised designership of software. That is, it's intended to facilitate the ability of separate teams to design and maintain software components, ...
Steve's user avatar
  • 8,949
1 vote

In OOP, what counts as a "getter"

Plenty of answers why getters are good or bad. But not what they are, which is the question. In C, structs have fields that anyone can access. Same for structs and classes in C++, except they are ...
gnasher729's user avatar
  • 45.7k

Only top scored, non community-wiki answers of a minimum length are eligible