diff --git a/Library/Homebrew/cxxstdlib.rb b/Library/Homebrew/cxxstdlib.rb
index 1b279c28b93a2c7017ef0d4d956c166960efe5b4..e2754c51b7a885b77e57180468b33fa5da517f0a 100644
--- a/Library/Homebrew/cxxstdlib.rb
+++ b/Library/Homebrew/cxxstdlib.rb
@@ -2,9 +2,11 @@
 
 require "compilers"
 
+# Combination of C++ standard library and compiler.
 class CxxStdlib
   include CompilerConstants
 
+  # Error for when a formula's dependency was built with a different C++ standard library.
   class CompatibilityError < StandardError
     def initialize(formula, dep, stdlib)
       super <<~EOS
@@ -17,8 +19,8 @@ class CxxStdlib
   def self.create(type, compiler)
     raise ArgumentError, "Invalid C++ stdlib type: #{type}" if type && ![:libstdcxx, :libcxx].include?(type)
 
-    klass = (compiler.to_s =~ GNU_GCC_REGEXP) ? GnuStdlib : AppleStdlib
-    klass.new(type, compiler)
+    apple_compiler = compiler.to_s.match?(GNU_GCC_REGEXP) ? false : true
+    CxxStdlib.new(type, compiler, apple_compiler)
   end
 
   def self.check_compatibility(formula, deps, keg, compiler)
@@ -35,9 +37,10 @@ class CxxStdlib
 
   attr_reader :type, :compiler
 
-  def initialize(type, compiler)
+  def initialize(type, compiler, apple_compiler)
     @type = type
     @compiler = compiler.to_sym
+    @apple_compiler = apple_compiler
   end
 
   # If either package doesn't use C++, all is well.
@@ -72,15 +75,7 @@ class CxxStdlib
     "#<#{self.class.name}: #{compiler} #{type}>"
   end
 
-  class AppleStdlib < CxxStdlib
-    def apple_compiler?
-      true
-    end
-  end
-
-  class GnuStdlib < CxxStdlib
-    def apple_compiler?
-      false
-    end
+  def apple_compiler?
+    @apple_compiler
   end
 end