Question: Module `A` relies on module `B`, and class `C` relies on modules `A` and `B`. If I include `A` and `B` into `C`, this works, but I do not like the fact that `A` has a dependency on another module that must be mixed in along with it for it to work.

What is the "right" way to mix in modules in this situation? Should `A` mix in `B` itself? What if `C` also uses `B` directly?

```
module B
  def g
    12
  end
end

module A
  def f
    2 * g
  end
end

class C
  include A, B

  def h
    3 * f
  end
end

```

Answer: 
Nothing is wrong with writing `include` redundantly. If `A` and `C` both rely on `B`, then include `B` in both `A` and `C`.

```
module B
  def g; 12 end
  def i; 7 end
end

module A
  include B
  def f; 2 * g end
end

class C
  include A, B
  def h; 3 * f * i end
end

```

If `C` does no rely on `B`, then include `B` only in `A`.

```
module B
  def g; 12 end
end

module A
  include B
  def f; 2 * g end
end

class C
  include A
  def h; 3 * f end
end

```
> 
> Module A has a method that relies on functionality found in module B. [...]. What is the "right" way to mix in modules in this situation? Should A mix in B itself? What if C also uses B directly?
> 
> 
> 

You've got few choice. Each of which should be chosen depending on the relationship between A, B and C.

The first one is to declare a module `D` that will define the shared functionality between `A` and `B`. In this way you can easily mix `D` with both `A` and `B` without worrying too much:

```
module D; ...; end
module A; include D; ...; end
module B; include D; ...; end

```

The other one that I can think of is to transform `A` and `B` into classes in order to use inheritance. Inheritance is good when having two classes that has a strong dependence relationship. If the functionality used by `A` is *strong enough* you should definitely choose this one:

```
class B; ...; end
class A < B; ...; end
class C < A; ...; end

```