Refactoring Shapes
You may or may not have used an object-oriented programming language thus far to build your ray tracer. Honestly, it really doesn’t matter! But since we need some kind of common vocabulary to describe the upcoming refactoring, let’s just agree to use terms like “classes,” “objects,” “parents,” and “inheritance.” Translate these concepts into your own environments accordingly.
The goal of this next step is to take your Sphere implementation, identify the functionality that will be common to all shapes, and refactor those bits into an abstract parent that all other shapes will inherit from. Once the common bits have been moved into the abstract parent, you’ll simplify your Sphere implementation by inheriting it from that parent. ...
Get The Ray Tracer Challenge now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.