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
1
vote
1 answer

How to solve that last "ask" in a complex calculation to conform "tell! don't ask!"?

today i was thinking about "tell! don't ask!" and experimenting with this code. interfaces: interface IValidationContext { void AddMessage(string text); bool IsValid { set; } } interface IValidation { void ValidateInput(Input input,…
mo.
  • 3,474
  • 1
  • 23
  • 20
1
vote
0 answers

Tell don't ask -- how does it apply to this example?

As a proxy for something real I am working on, consider building a model. We'd have a Parts class representing model parts, complete with methods to manufacture the part based on given parameters, to validate, etc. We have a Glue class which does…
Fadecomic
  • 1,220
  • 1
  • 10
  • 23
0
votes
1 answer

How to have all component logic inside of it and export it to parent components

I have a modal component that is being used to display a form for the user. This modal accepts three parameters: is_visible (if the modal is shown), toggleModal (state function for managing ifthe modal will show or not), passport_id (irrelevant…
0
votes
3 answers

How to test an object when I can't access state?

I have a factory class that creates an object based on a parameter it receives. The parameter is an identifier that tells it which object it should create. Its first step is to use the data access layer to pull information for the object. Its next…
johnB
  • 536
  • 1
  • 6
  • 14
0
votes
1 answer

Tell-dont-ask princible uses more memory, how to make a compromise?

class Operation { private $op; public function __construct() { $this->op = []; for ($i = 1; $i < 1000; $i++) { $this->op[] = rand(1,9999); } } public function getOps() { …
John Smith
  • 6,129
  • 12
  • 68
  • 123
0
votes
1 answer

Single responsibility principle in API

Please have a look at following piece of code: public interface ICultureService { List GetCultures(); bool IsCultureSupported(Culture culture); Culture GetFallbackCulture(); } We found that most of the consumers first call…
0
votes
4 answers

Initializing Domain Objects - observing SOLID, Tell, Don't Ask

I'm trying to follow some of the more current design principles including SOLID and Domain Driven Design. My question is around how people handle "Initializing" Domain Objects. Here's a simple example: Based on SOLID, I should not depend on…
0
votes
2 answers

Tell don't ask and shared state between tasks

In this simple example (ofcourse my real world problem is a tad more complex, although the basics are the same), how do I enforce tell dont ask to the max? Id like to maximize tell dont ask in the process method, in its current state its harder to…
MatteS
  • 1,542
  • 1
  • 16
  • 35
0
votes
1 answer

How to unit test a parser which returns 'tell-dont-ask' objects?

I have two classes, Parser and Item. The Parser class parses some structured document and returns Item-objects if you call something like Parser::GetItem(int some_id). The Item class was written with the "Tell - don't ask" principle in mind. By that…
lslah
  • 556
  • 8
  • 17
0
votes
2 answers

Using Event to apply TellDontAsk pattern

I have tried to raise event in cSharp to notify code change in my application in order to have tellDontAsk scenario. I have simple class that implement from event class public class SimpleTellDontAsk : ISomeEvent { public void doSomething(string…
wikinevis
  • 189
  • 1
  • 2
  • 11
0
votes
1 answer

Rails ActiveRecord tell don't ask

Having two classes like this: class Site < ActiveRecord::Base has_one :subscription, dependent: :destroy def self.hostname_active?(hostname) site = where(hostname: hostname) site.exists? && site.first.active? end def active? …
Yeggeps
  • 2,055
  • 2
  • 25
  • 34
0
votes
1 answer

How would you implement the "tell don't ask" principle in HAML?

Here's the thing. I have a button that, depending on the scenario, will behave, look and have different text. Here's how it, roughly, looks like at the moment: - if params[:param_A] && @statement_A %span.button.cancel_button{attribute: "value_B"} …
1
2