Timeline for Zero behavior objects in OOP - my design dilemma
Current License: CC BY-SA 3.0
36 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 27, 2023 at 8:09 | comment | added | yegor256 | This blog post of mine may also be helpful: Getters/Setters. Evil. Period. | |
| Nov 5, 2017 at 22:27 | comment | added | Ryan Reich | This question is very old and my comment is not really an answer, so it will remain just a comment. I'd say that you have discovered the joys of functional programming; in particular, you describe basic algebraic data types and type classes as Haskell would call them: that is, types with just data and types with just methods. | |
| Mar 29, 2016 at 16:38 | comment | added | sara | Regarding Cards and Players, to me it seems obvious that a player is composed by (among other things) a set of Cards (or possibly even a Hand abstraction). A player can only see it's own cards, although a player probably needs to be able to be queried for the current number of cards int it's hand. | |
| Jan 13, 2015 at 8:08 | history | protected | gnat | ||
| Apr 23, 2014 at 20:02 | comment | added | Thomas Eding | FWIW, the visibility of a card to a player is determined by neither of them. Instead games determine it. Thus in addition to Card and Player, you want a Game object that has the member bool Game::IsVisibleTo(Card, Player). | |
| Apr 13, 2014 at 5:21 | history | tweeted | twitter.com/#!/StackProgrammer/status/455214048939102208 | ||
| Apr 7, 2014 at 7:44 | vote | accept | RokL | ||
| Apr 4, 2014 at 22:36 | comment | added | supercat | ...each of which simply holds whatever was put there, is apt to be cleaner than trying to use something fancier. The real meaning of minimum and maximum, along with any corner cases, are going to be determined by whatever method is suppose to put those values into the MinMaxRange object. | |
| Apr 4, 2014 at 22:34 | comment | added | supercat | @Montagist: Data types which simply aggregate a few discrete values or traits without any particular attached behavior are often useful. Consider, for example, what should be returned by a function to compute the minimum and maximum values in a collection of BigInteger; since the time required to find both the minimum and the maximum would be much less than twice than the time required to find one or the other, having one call return both values is useful. A type which simply encapsulates a BigInteger called minimum and one called maximum,... | |
| Apr 4, 2014 at 21:03 | comment | added | Montagist | I think behavior-less classes are a "bad smell" because so many are likely to implement anemic models. In the case of the answer to this, though, I'd posit that - like the answer-er says - a card needn't know anything, so if I came across a card-game app that generally had logic and data in classes but represented cards as structs, I'd consider it a good design choice. | |
| Apr 4, 2014 at 17:11 | comment | added | Frank Hileman | Behavior-less classes are not an anti-pattern. They are simply not very object-oriented, according to some people's definition of object-oriented. That does not make them less useful. If you attempt to make code more and more general purpose, it becomes less and less likely that data and behavior can stay together in a class, because general purpose methods operate on any data. It comes down to object-oriented versus functional. Each has advantages and disadvantages. | |
| Apr 3, 2014 at 8:17 | comment | added | user21123 | Martin Fowler and Eric Evans, among others. martinfowler.com/bliki/AnemicDomainModel.html | |
| Apr 3, 2014 at 4:35 | answer | added | Harsha | timeline score: 4 | |
| Apr 3, 2014 at 3:49 | comment | added | James Anderson | Who says beheaviourless classes are an anti-pattern? | |
| Apr 3, 2014 at 3:31 | answer | added | h.j.k. | timeline score: 1 | |
| Apr 2, 2014 at 19:07 | answer | added | Diane M | timeline score: 4 | |
| Apr 2, 2014 at 17:40 | answer | added | Eric Lippert | timeline score: 161 | |
| Apr 2, 2014 at 17:35 | comment | added | Robert Harvey | en.wikipedia.org/wiki/Data_transfer_object | |
| Apr 2, 2014 at 17:16 | answer | added | supercat | timeline score: 3 | |
| Apr 2, 2014 at 16:46 | answer | added | RibaldEddie | timeline score: 9 | |
| Apr 2, 2014 at 16:40 | comment | added | luke1985 | Stay out of all the so called "Best practices" and don't listen to blind rules. Usually they make things much harder. There are too many "wise" people with all they dirty stuff. Instead try to learn and discover for yourself. | |
| Apr 2, 2014 at 14:49 | comment | added | Ingo | You can even enhance your data objects by making them immutable. | |
| Apr 2, 2014 at 13:58 | comment | added | Thiago Silva | This is a very good question, and well posted -- contrary to some of the other comments, I'd say. It shows clearly how naive or incomplete most advices on how to structure program are -- and how difficult it is to do it, and how unreachable a proper design is in many situations no matter how much one strives to do it right. And although an obvious answer to the specific question is multi-methods, the underlying problem of designing persists. | |
| Apr 2, 2014 at 13:56 | answer | added | Doval | timeline score: 18 | |
| Apr 2, 2014 at 13:53 | comment | added | pdr | Also related: stackoverflow.com/questions/7177904/worker-vs-data-class | |
| Apr 2, 2014 at 13:52 | answer | added | Konrad Morawski | timeline score: 47 | |
| Apr 2, 2014 at 13:30 | comment | added | Doc Brown | Related: programmers.stackexchange.com/questions/224941/… | |
| Apr 2, 2014 at 13:12 | review | Close votes | |||
| Apr 8, 2014 at 20:03 | |||||
| Apr 2, 2014 at 13:09 | comment | added | Doc Brown | I guess the problem lies in the fact that there have been different schools for "Object Orientation" in the past - the way it was originally meant by people like Alan Kay (see geekswithblogs.net/theArchitectsNapkin/archive/2013/09/08/…), and the way is was taught in context of OOA/OOD by those people from Rational (en.wikipedia.org/wiki/Object-oriented_analysis_and_design). | |
| Apr 2, 2014 at 12:59 | answer | added | amon | timeline score: 29 | |
| Apr 2, 2014 at 12:57 | comment | added | RokL | It is, because data and behaviour are completely and entirely separated. I might as well be using structs and global functions. | |
| Apr 2, 2014 at 12:55 | comment | added | Doc Brown | "This is clearly against the principal idea of OOP" - no, its not, but its a common fallacy. | |
| Apr 2, 2014 at 12:53 | comment | added | pdr | Some of your premises here are completely wrong, which is going to make answering the underlying question very difficult. Keep your questions as concise and opinion-free as you can and you will get better answers. | |
| Apr 2, 2014 at 12:37 | answer | added | DougM | timeline score: 9 | |
| Apr 2, 2014 at 12:32 | history | edited | RokL | CC BY-SA 3.0 | added 755 characters in body |
| Apr 2, 2014 at 12:23 | history | asked | RokL | CC BY-SA 3.0 |