Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 587545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:13:25+00:00 2026-05-13T15:13:25+00:00

How would you adhere to the Tell, don’t ask principle (henceforth the principle) in

  • 0

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 var fallingPiece:Piece;
    private var blockGrid:BlockGrid;
    ...
    public function moveFallingPiece(xDirection:int, yDirection:int):void
    {
        blockGrid.movePiece(fallingPiece, xDirection, yDirection);
    }
} 

Once fallingPiece is placed in the bottom row of BlockGrid, it should no longer be the “fallingPiece”. Am I right in that I’m not violating the principle with the following?

if(blockGrid.getPiecePosition(piece).y == 0)
{
    fallingPiece = null;
}

But is that really different from this, which I think clearly violates the principle?

public function moveFallingPiece(xDirection:int, yDirection:int):void
{
    if(blockGrid.getPiecePosition(piece).y > 0)
    {
        blockGrid.movePiece(fallingPiece, xDirection, yDirection);
    }
    else
    {
        fallingPiece = null;
    }
}

I’m not assuming that I’ve designed these class relationships in the proper way to work with the principle. Please advice on an alternate design if that’s what I’m missing.


EDIT, Proposed solution:

I went with the answers proposing “command feedback” via events. Board tells BlockGrid to move a piece. BlockGrid’s movePiece method dispatches MOVED_TO or MOVE_FAILED events depending on the result, which Board can listen to and use to determine whether a piece has stopped falling. Please don’t hesitate to provide feedback on this solution.

public class Board
{
    ...
    public function Board()
    {
        ...
        blockGrid.addEventListener(PieceMoveEvent.MOVE_FAILED, onPieceMoveFailed);
        ...
    }

    public function moveFallingPiece(xDirection:int, yDirection:int):void
    {
            blockGrid.movePiece(fallingPiece, xDirection, yDirection);
    }

    public function onPieceMoveFailed(event:MovePieceEvent):void
    {
        if(event.instance == currentlyFallingPiece && event.fromPosition.y != event.toPosition.y)
        {
             currentlyFallingPiece = null;
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:13:25+00:00Added an answer on May 13, 2026 at 3:13 pm

    I think, to better follow the Tell, Don’t Ask principle, you should have blockGrid notifying your Board class when fallingPiece has reaches it’s resting point. In both scenarios above, you are asking blockGrid if the piece’s position.y == 0 in order to determine whether or not fallingPiece should be null. Instead, you want blockGrid to tell the Board class that fallingPiece.y has hit 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question How do I adhere to the Tell, Don't Ask principle when performing a
In an effort to adhere to the Dry Principle I have some code I
Would be possible to extend this kind of layout so that I can have
Would it be possible to extract the following information from logs? Start up/Shut down
Would like someone to take a look at my script and tell me where
Let's assume I'm implementing a Winforms UI where all commands adhere to the following
I'm continuing to learn C and would like to adhere to whatever is the
I am trying to adhere to best multi-layer design practices, and don't want my
I have a simple C (of CRUD) function, and I'd like to send a
I wrote a regular expression to validate strings that must adhere to the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.