Java Reference
In-Depth Information
The Substance_1 class uses the atomic weight of a chemical when it calculates the number
of moles of a modeled quantity of substance. For example, 10 grams of sulfur contains 10/32
moles:
public double getMoles()
{
return grams / atomicWeight;
}
The molality of a substance combines information about the mass of a particular batch and
the immutable atomic weight of the substance. To support the calculation of molality,
developers at Oozinoz have placed mass and atomic weight together in the Substance_1
class. The molality of substances, combined with an understanding of chemical reactions,
determines the amount of each substance that must appear in a chemical mixture. (For
example, two moles of hydrogen and one mole of oxygen can make a mole of H 2 O—water.)
At Oozinoz, no mixture is more common than the black powder that is part of most fireworks.
Figure 13.2 shows an object diagram of a batch of black powder.
Figure 13.2. A batch of black powder contains saltpeter, sulfur, and carbon.
Given the proliferation of chemicals at Oozinoz, you might decide to model chemicals with
shared, flyweight objects. As a first step, suppose that you decide to refactor the
Substance_1 class, extracting its immutable part into a Chemical_1 class.
Search WWH ::




Custom Search