5 Too Common Myths About Languages Broken Down

I love learning languages. Each new language brings a world of discoveries and makes me excited like a little kid who just got a new toy. On my journey to learn 6 languages, I’ve been able to break…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Refactoring Shapes

The Ray Tracer Challenge — by Jamis Buck (55 / 108)

👈 Chapter 9 Planes | TOC | Implementing a Plane 👉

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.

So, what will all shapes have in common? Here’s a list that you can start with:

Later chapters, like Chapter 14, Groups, and Chapter 16, Constructive Solid Geometry (CSG), will add to that list, but those four items are all you need to worry about for now.

Begin by writing some tests that describe what this refactoring should look like when it’s done. Because this will depend heavily on your programming language and how you’ve architected things so far, consider the following tests to be guidelines — ideas for how to build your own tests.

Add a comment

Related posts:

K2 LIQUID SPRAY

BUY K2 POWDER ONLINE. “K2 LIQUID SPRAY” is published by Larryscottman.

Representing Four Dimensions

Unlock the secrets to creating random mazes! Whether you're a game developer, an algorithm connoisseur, or simply in search of a new puzzle, you're about to level up. Learn algorithms to randomly generate mazes in a variety of shapes, sizes, and dimensions. Bend them into Moebius strips, fold them into cubes, and wrap them aroun

A Tibetan in Berkeley

A Tibetan man in a Tibetan shop. Essence of Tibetan is a Tibetan shop located at College Avenue in Berkeley, California. The Tibetan population in the U.S. is still a small community with 5,147 US…