Questions tagged [tell-dont-ask]

Tell-don't-ask is an approach to object-oriented design focused on telling objects what you want them to do rather than asking them questions about their state, make a decision, and then tell them what to do.

See the original Tell Don't Ask post for a full account.

Questions having this tag will relate to test-driven design, mock objects, or object-oriented design.

27 questions
25
votes
6 answers

Aren't Information Expert & Tell Don't Ask at odds with Single Responsibility Principle?

Information-Expert, Tell-Don't-Ask, and SRP are often mentioned together as best practices. But I think they are at odds. Here is what I'm talking about. Code that favors SRP but violates Tell-Don't-Ask & Info-Expert: Customer bob = ...; //…
18
votes
4 answers

Tell, Don't Ask and Single Responsibility - doing new things with data in a class

I've got a case where "Tell, don't Ask" seems to conflict with the "Single responsibility" principle. I've looked at other discussions on the subject but not yet been able to work out the most appropriate object oriented approach for this…
Bob
  • 1,037
  • 1
  • 9
  • 14
7
votes
5 answers

Tell, Don't Ask Principle and Password Expiration

Trying to keep with pragmatic programming principles, I'm trying to decide on how to handle user password changes based on the "Tell, Don't Ask" principle. I have a user object whose password expires every 30 days. I need to be able to show a…
Hupperware
  • 979
  • 1
  • 6
  • 15
7
votes
4 answers

"Tell, Don't Ask" over multiple domain objects

Question How do I adhere to the "Tell, Don't Ask" principle when performing a function involving multiple objects. Example - Generating a Report I have the following objects (illustrative purposes only): Car, Horse, Rabbit There is no…
djcredo
  • 1,147
  • 2
  • 10
  • 14
5
votes
3 answers

Does "tell, don't ask" apply to user input validation?

I somehow must have overlooked the "tell, don't ask" OOP principle all these years because I just learned about it a couple days ago for the first time. But the context was a discussion about validation code that had been moved out of an ASP.NET web…
Jon Davis
  • 6,562
  • 5
  • 43
  • 60
5
votes
6 answers

Simple Scenario, How to Incorporate Tell Don't Ask?

I'm trying to model a basic scenario involving a Person and a Seat. A Person has a Status property: Sitting or Standing. A seat has a Seated property that specifies the Person that is currently sitting in it. Also, a Seat is special in that it only…
snazzer
  • 449
  • 1
  • 5
  • 10
4
votes
4 answers

How to think "Tell, don't ask" in this simple example?

How would you adhere to the "Tell, don't ask" principle (henceforth "the principle") in the following simple scenario? In a Tetris game, I have Board, BlockGrid and Piece classes relevant to the following example: public class Board { private…
Stiggler
  • 2,800
  • 20
  • 21
4
votes
1 answer

Doesn't the Factory pattern, violate the "Tell, Don't Ask" principle?

Procedural code gets information then makes decisions. Object-oriented code tells objects to do things. Alec Sharp When we are using the Factory pattern, we make decision, based on a property of a class except than the factory class, so this,…
Masoud
  • 8,020
  • 12
  • 62
  • 123
3
votes
2 answers

How to unit-test in "tell, don't ask" follower classes?

I think the issue is explained best with an example. public class MyService { private OtherService theOther; public void setTheOther(OtherService srv) { theOther = srv; } public void myBusinessStuffFor(int id) { …
Per Newgro
  • 93
  • 2
  • 11
3
votes
6 answers

How can I avoid getters AND avoid hard coding the UI?

I want to print a description of a warrior to the console that will include the warrior's strength and the warrior's weapon in the form This warrior uses a For example: This strong warrior uses a butter knife. Edit for…
Rupert Madden-Abbott
  • 12,899
  • 14
  • 59
  • 74
3
votes
1 answer

Is creating a lot of private classes bad style?

I am doing a project in Java which has a lot of methods that require multiple return objects. For this I have to keep creating private classes which encapsulate the return objects. The objects make sense as a FontResult in my code will return the…
kabeersvohra
  • 1,049
  • 1
  • 14
  • 31
2
votes
1 answer

Single Responsibility(SRP) vs Tell Don't Ask(TDA)?

I understand that many design principles conflict with each other in some cases . So, we have to weigh them and see which one is more beneficial. Till now I was aware of SRP principle and did my lot of designs solely based on that but internally I…
emilly
  • 10,060
  • 33
  • 97
  • 172
2
votes
2 answers

Can I use mvc without getters and setters?

If I don't want to expose the state of my object, but I still need to display it (in HTML, XML or JSON let's say), how would I go about doing that in an MVC environment. Does it make sense to have an export method which exports a dumbed down…
blockhead
  • 9,655
  • 3
  • 43
  • 69
2
votes
4 answers

Good case for Tell, Don't Ask

Say I have two objects: Map Table At the moment I have something like this: Map.MapTable(Table tab); <- Static MapTable method. which checks if the table is mappable and then maps it but also has to check for null table. Would it make more sense…
Nathan W
  • 54,475
  • 27
  • 99
  • 146
1
vote
1 answer

"Tell, don't ask" when one class is doing and storing calculations with data from another

Please tell me if I'm applying the Tell, dont't ask principle in right way in this example. I have two classes, CalculationResults has a function calculateMe(), which uses Data to make some calculations. It is important that it stores the results.…
1
2