DEV Community

Candace Eckels
Candace Eckels

Posted on

Inheritance and Modules

I've learned that the major difference between these to tools is the use case. Inheritance I will use if I need to instantiate a class and then the next class I use builds off that previous class(I want it to mimic a 'parent-child' relationship). Whereas modules I would use when I didn't need to instantiate and instance.

I have found that this is best used for calculations that are used across multiple classes. An example might be a total calculation. That can be used in multiple classes. Instead of writing out this total calculation for every class I need it in I can create a module that holds my method and then have my classes call on that one total method to find my totals.

If you wanna checkout my project click here!

Latest comments (0)