3 ms·
One example I often give is the nabla operator from vector calculus that is in one form or another used in any fluid dynamics code. If you define nabla as a fun
by milancurcic 8y ago
One example I often give is the nabla operator from vector calculus that is in one form or another used in any fluid dynamics code. If you define nabla as a function that operates on a Field type, and Scalar and Vector types extend the Field type, then nabla can be coded to return a gradient (Vector) if passed a Scalar, and divergence (Scalar) if passed a Vector. Polymorphism is an elegant way to implement this.