O'Reilly logo

Essential Skills for the Agile Developer: A Guide to Better Programming and Design by Amir Kolsky, Ken Pugh, Scott Bain, Alan Shalloway

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix C. Encapsulating Primitives

Encapsulation in object-oriented programming is often interpreted as making sure classes do not expose their implementation. You can go beyond this interpretation and encapsulate all the concepts in your program. Encapsulating implementations in abstract data types provides benefits in code readability, testability, and quality.1

Encapsulating Primitives in Abstract Data Types

Let’s start with a typical method.

double getDiscount(double orderTotal) {}

With encapsulation, we are not concerned with the implementation of getDiscount(), only its interface: the signature of the method. Looking just at the signature, it’s easy to envision what the method does. It receives the total for an order and returns the discount. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required