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 942109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:13:14+00:00 2026-05-15T22:13:14+00:00

I’m working on a project for visually tracking trains. I’ve refactored the object relationship

  • 0

I’m working on a project for visually tracking trains. I’ve refactored the object relationship between the trains, the tracks, and the respective drawing classes for each several times, and I’m not happy with any of them. Maybe you guys can help me out here.

Here are the interfaces to the objects I’ve got now.

Tracks:

  • addControlPoint(IntPoint point)
  • getPointAtPosition(float positionOnTheCurve)
  • getTangentAtPosition(float positionOnTheCurve)
  • getMaxPosition()

TrackDrawer:

  • setGraphicsContext(Graphics g);
  • draw(Tracks track);

Train:

  • set/getTrack(Tracks track)
  • set/getTrackPosition(float position)
  • set/getSpeed(int speed)
  • moveForward(elapsedTime)

TrainDrawer:

  • setGraphicsContext(Graphics g)
  • draw(Train train)

And here’s how they’re being used at the moment.

init() {
    Tracks track = new Tracks();
    track.addPoint( point1 );
    track.addPoint( point2 );
    track.addPoint( point3 );  

    Train train = new Train();
    train.setTrack(track);
    train.setPosition(0);
}

run() {
   while (running) {
       elapsedTime = calcTime();
       update(elapsedTime);
       Graphics g = getGraphics();
       draw(g);
   }
}

update(long elapsedTime) {
    train.setSpeed(10);
    train.moveForward(elapsedTime);
}

draw(Graphics g) {
    trackDrawer.draw(track);
    trainDrawer.draw(train);
}

Here are a couple of specific questions:

  1. Does it make sense that a train depends on a track? I think it does, as a train without a track makes little sense in the real world.

  2. In order to draw the train, I need to find out the direction the train is facing on the tracks by calculating a tangent on the track itself. This causes a dependency of Track inside of TrainDrawer, which I don’t care for. However, I don’t think it necessarily makes sense to make Train responsible for calculating the directional vector (tangent) when it’s ONLY needed for drawing the train, and for no other reason.

  3. In general, what is the best practice for creating objects that need to be drawn in some fashion? Many people are telling me that the train should know how to draw itself, but that seems to put too many dependencies on the train itself. It doesn’t feel right.

  • 1 1 Answer
  • 1 View
  • 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-15T22:13:15+00:00Added an answer on May 15, 2026 at 10:13 pm

    My first impression is that TrainDrawer and TrackDrawer are the source of the problem and should not exist.

    Following the model-view approach, Trains and Tracks are model entities, neither of which has the other. If you consider a Draftsman object (corresponding to the “view”), the draftsman gathers information from Tracks and Trains and renders a coherent whole.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.