35
votes
How do interactions between objects work?
In your design, coins need to know about vending machines. This unnecessary coupling seems to be a wrong start:
The vending machine’s responsibility is to provide a product if the price is paid. The ...
34
votes
Accepted
Unable to solve mystery of functions in Javascript
I am trying to understand behind the curtain scenes of Javascript and kind of stuck in understanding the creation of built in objects, specially Object and Function and the relation between them.
It ...
26
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 ...
19
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 ...
16
votes
Accepted
How do interactions between objects work?
I'm not going to criticize your design because I see that it's not the point. Indeed coins shouldn't know about vending machines, and the related arguments, are valid. Let's assume that these classes ...
13
votes
How do interactions between objects work?
The code is being too literal in attempting to model the real world. Object oriented programming does not need to model the real world. Instead, it should model the business process of purchasing ...
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 ...
10
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 ...
8
votes
How to avoid != null statements?
Deciding whether or not null is a allowed as an object value is a decision that you must make consciously for your project.
You don't have to accept a language construct just because it exists; in ...
7
votes
Why are classes named "class"?
Just did some googling and it seems the terms were invented by Ole-Johan Dahl and Kristen Nygaard for their Simula programming language
We chose the terms “class” and “objects” of classes for our ...
6
votes
Design pattern for objects in invalid states
No no no no.
First, stop using floating point numbers to represent base 10 money. Ints work fine if you count pennies and remember to add the decimal point when presenting them as dollars.
...
6
votes
Unable to solve mystery of functions in Javascript
You have many excellent answers already, but I just want to give a short and clear answer to your answer about how all of this works, and that answer is:
MAGIC!!!
Really, that's it.
The people who ...
6
votes
How to avoid != null statements?
In Java 8, a new feature was added: Optional<>. This is for fields that may or may not be there and is an alternative to using null checks.
If you use Optional, then you can check whether or ...
6
votes
If methods are actions that an object can perform, how do we represent abstract objects?
First, let's look at what "object-oriented" actually means.
The very first object-oriented programming language was Simula (1960). As the name implies, it was designed for simulations. If ...
5
votes
Accepted
How to avoid != null statements?
The dilemma
If a variable with null value gets used in your program causing a NullPointerException, this is clearly a situation in your program which you did not expect. You must ask yourself the ...
5
votes
Accepted
Object vs Primitive: Not use long primitive because... the default value is zero?
If you need a representation for "not set", then Long is a good choice, with null standing for "not set". If that isn't needed, don't waste time and space with the unnecessary boxing and unboxing ...
5
votes
Where to put the behaviour of DTOs ? Object vs Data structure clean code
DTOs are not part of the domain model, and do not have any behaviour. DTOs represent the data structures that are transferred across your system boundary, e.g. data that is serialized to be sent ...
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 ...
4
votes
Should we consider immutability for local scoped variables
The reviewer is right:
Modifying the variable in a way you do makes the code difficult to reason about. Actually, it makes the code quite cryptic.
Imagine I'm barely using the method from your ...
4
votes
Why are classes named "class"?
Because 'class' is a great choice for the concept?
"A set or category of things having some property or attribute in common and differentiated from others by kind, type, or quality."
https://en....
4
votes
Accepted
Should only static functions print to screen?
I think there is no widely known principle stating that only static methods should print to screen.
For example, a CLI app can have injected loggers inside its' objects. Such loggers would print to a ...
4
votes
How do interactions between objects work?
Coin should have only getters about their value and no insert method since it doesn't have any responsability other that being a legit coin.
VendingMachine should have an Accept(Coin* coin) method.
...
4
votes
Accepted
Opaque objects on the stack / in structs
The typical way to create allocatable opaque types is to give up on the opaqueness in the strictest sense, and to declare access to internals as UB. For example, the POSIX pid_t type happens to be a ...
4
votes
Services: Which structure is a better idea?
If you can't decide, it's because you're not making your decision based on things that really "matter" to you.
If your objects would express the actual behavior of the application you're ...
3
votes
Should I be creating more objects in Java?
Should I be creating more objects in Java?
If you can create more useful classes you should. As you do other classes should be getting smaller.
...messing around with a program that essentially ...
3
votes
Unable to solve mystery of functions in Javascript
From ECMA spec 1
ECMAScript does not contain proper classes such as those in C++,
Smalltalk, or Java, but rather, supports constructors which create
objects by executing code that allocates ...
3
votes
Accepted
Design pattern for objects in invalid states
How are responsibilities between classes?
There is no single answer to that question. It's first a question of responsibilities:
Shall using classes be responsible for verifying if they can do the ...
3
votes
Why do we need factories in the first place?
The real question is what you want to achieve, and either achieve it in C++, or in another language if you think it would suit the needs better.
Why can't virtual constructors exist in C++?
Imagine ...
3
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 ...
3
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
object × 96java × 25
object-oriented × 22
class × 21
object-oriented-design × 15
design × 11
javascript × 10
c# × 8
design-patterns × 8
c++ × 8
php × 7
python × 5
array × 4
constructors × 4
c × 3
multithreading × 3
exceptions × 3
data × 3
instance × 3
database × 2
programming-languages × 2
database-design × 2
coding-style × 2
performance × 2
uml × 2