TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
48
11.8k
How can I best divide up this constructor?
Oct 2 2019 3:50 PM
I am running into the problem of my constructors becoming too large. Please see the example for a Vehicle class below:
public
Vehicle(
double
width,
double
length,
double
turningRadius,
double
angle,
double
middleX,
double
middleY,
double
velocity,
double
steeringAngle,
double
velocityMax,
double
velocityChange)
With 10 parts, this is already quite large. I plan to add other aspects to this, such as color, gear shifting, friction, number of tires, etc. My question is, how do I restructure this so that it is more redable and manageable?
I have considered things like combining middleX and middleY into a point, or making a struct for the 3 velocity-related items, or even setting nothing in the constructor and setting each item or group of items with its own function, but that gets messy.
How can I address this issue, when do I know how much is too much, and how can I fix it?
Reply
Answers (
3
)
How to highlight a particular part of the image ?
Multi TCP Client in single application with multi TCP server