Note that there are some explanatory texts on larger screens.

plurals
  1. POIs delegating calls between classes bad practice?
    primarykey
    data
    text
    <p>I know that delegating from one method to another in the same class is okay as it reduces code duplication, but is delegating calls to other class types considered bad practice?</p> <p>For example:</p> <p>Doing this is okay.</p> <pre class="lang-c prettyprint-override"> <code> double Point::GetDistanceFrom(const Point& point) const { return GetDistanceFrom(this->GetX(), this->GetY(), point.GetX(), point.GetY()); } double Point::GetDistanceFrom(const Point& one, const Point& two) { return GetDistanceFrom(one.GetX(), one.GetY(), two.GetX(), two.GetY()); } double Point::GetDistanceFrom(double x1, double y1, double x2, double y2) { return std::sqrt(GetDistanceFromSquared(x1, y1, x2, y2)); } double Point::GetDistanceFromSquared(double x1, double y1, double x2, double y2) { x2 -= x1; y2 -= y1; return (x2 * x2 + y2 * y2); } double Point::GetDistanceFromSquared(const Point& one, const Point& two) { return GetDistanceFromSquared(one.GetX(), one.GetY(), two.GetX(), two.GetY()); } </code> </pre> <p>But what about this?</p> <pre class="lang-c prettyprint-override"> <code> double Point::GetDistanceFrom(const Line& line, bool isInfinite) const { if(isInfinite) return line.ptLineDist(line.GetPointOne().GetX(), line.GetPointOne().GetY(), line.GetPointTwo().GetX(), line.GetPointTwo().GetY(), this->GetX(), this->GetY()); return line.ptSegDist(line.GetPointOne().GetX(), line.GetPointOne().GetY(), line.GetPointTwo().GetX(), line.GetPointTwo().GetY(), this->GetX(), this->GetY()); } </code> </pre> <p>And this?</p> <pre class="lang-c prettyprint-override"> <code> double Line::GetDistanceFrom(const Point& point, bool isInfinite) const { return point.GetDistanceFrom(*this, isInfinite); } </code> </pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload