Timeline for How do interactions between objects work?
Current License: CC BY-SA 4.0
29 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 14, 2023 at 20:48 | history | edited | Christophe |
edited tags
|
|
Jun 7, 2021 at 6:00 | history | tweeted | twitter.com/StackSoftEng/status/1401781012451954688 | ||
Jun 4, 2021 at 15:16 | answer | added | Matthieu M. | timeline score: 0 | |
Jun 4, 2021 at 10:20 | comment | added | sbecker | In disregard to the actual question: Please read up on basics of current C++. Avoid using new and delete. Manual memory management is not necessary here. It seems you come from a C# background. The languages are very different. Skipping those basics to implement OOP in C++ might make it more difficult to understand OOP in the long term. | |
Jun 4, 2021 at 7:22 | comment | added | WW. | This is a difficult question to answer IMHO because the example is too simple. We model the things we care about using abstractions in code. But here we are given no clues about what we care. Do we care to try and track a single coin through it's life as a coin? Do we want to know how often the cash in the vending machine needs to be cleared? Without knowing the goal it's not possible to come up with a good model for these objects to interact. Everybody will be talking at cross-purposes in the comments and answers as a result. | |
Jun 3, 2021 at 18:05 | vote | accept | CommunityBot | ||
Jun 3, 2021 at 17:11 | answer | added | Kaz | timeline score: 16 | |
Jun 3, 2021 at 11:46 | vote | accept | CommunityBot | ||
Jun 3, 2021 at 12:05 | |||||
S Jun 3, 2021 at 11:46 | history | suggested | Mark H |
Add tag for language so Java programmers aren't confused
|
|
Jun 3, 2021 at 11:27 | vote | accept | CommunityBot | ||
Jun 3, 2021 at 11:27 | |||||
Jun 3, 2021 at 9:19 | history | protected | gnat | ||
Jun 3, 2021 at 4:19 | review | Suggested edits | |||
S Jun 3, 2021 at 11:46 | |||||
Jun 3, 2021 at 0:20 | answer | added | TCooper | timeline score: 2 | |
Jun 2, 2021 at 19:52 | history | edited | Christophe |
edited tags
|
|
Jun 2, 2021 at 19:22 | comment | added | Filip Milovanović |
If you for some reason prefer to think of the coin as the initiator, a key of sorts, you could just have coin->InsertInto(vm) , and than inside of that have vm->UpdateValue(amount); vm->UpdateDisplay() (or something). You don't have to have this conceptual Visitor-like Insert/Accept cycle. What I'm trying to say is that as the designer, you have the power over the conceptual model, the structure, and the names - you have the power to make things more or less intuitive for the user (another programmer, or future you). The reason this design is confusing is because you made it confusing. 2/2
|
|
Jun 2, 2021 at 19:22 | comment | added | Filip Milovanović |
"The interaction is represented by the functions InsertCoin() and Insert()" - nothing in OOP says you have to do it that way; how you represent the interaction can vary for the same problem (two devs may come up with a different structure), and it depends on how you think about the problem and on the needs of your application. E.g. if you're thinking of the Vending Machine as a primary object, you could just have vending_machine->AcceptCoin(coin) (and no Insert method on coin; still, the machine could interrogate the coin for its value). 1/1
|
|
S Jun 2, 2021 at 19:11 | history | suggested | TankorSmash | CC BY-SA 4.0 |
add code formatting
|
Jun 2, 2021 at 18:56 | review | Close votes | |||
Jun 7, 2021 at 3:07 | |||||
Jun 2, 2021 at 18:32 | comment | added | Konrad Rudolph | The main reason why your main function is confusing is because well over 50% of it is unnecessary clutter. Clutter is the enemy of course readability. Learn to avoid it. | |
Jun 2, 2021 at 18:31 | review | Suggested edits | |||
S Jun 2, 2021 at 19:11 | |||||
Jun 2, 2021 at 17:07 | history | became hot network question | |||
Jun 2, 2021 at 16:05 | comment | added | Greg Burghardt | @JacquesB has a very good question. I was assuming you were writing software for a real world vending machine. A vending machine simulator would certainly change the abstractions that must be built. | |
Jun 2, 2021 at 15:44 | answer | added | Tulains Córdova | timeline score: 4 | |
Jun 2, 2021 at 14:23 | answer | added | Christophe | timeline score: 35 | |
Jun 2, 2021 at 14:10 | comment | added | JacquesB | Are you writing software for a real-world vending machine, or you simulating a vending machine in software? | |
Jun 2, 2021 at 13:16 | answer | added | Greg Burghardt | timeline score: 13 | |
Jun 2, 2021 at 10:46 | comment | added | jonrsharpe | In your case the method called on the first line also invokes the method called on the second, so you're double-counting. | |
Jun 2, 2021 at 9:44 | answer | added | JonasH | timeline score: 1 | |
Jun 2, 2021 at 9:07 | history | asked | user362602 | CC BY-SA 4.0 |