Why Encapsulation Matters


In this article, they don’t show us examples of encapsulation but instead explain to us the importance of it and why we do it as software engineers. Initially, they start off with how encapsulation helps us hide the complexity of our code. The beauty of hiding our code is not having to understand all the details in order to be able to use it, we just need to understand a broader abstract concept and how it works and how we interact with it. They also explain to us what happens when are not able to achieve the proper levels of encapsulation in our design. That article continues as to why we need accessor and mutator methods in Java.


The reason why I chose this article was because in class we have done a lot coding in regards to encapsulation and I thought that this would help me fully grasp the purpose and meaning of encapsulation. Encapsulation is the very essence of API’s and how they work and being able to understand this is very important since we may be creating API’s in the future.

What I’ve Learned:

Encapsulation is more than just defining accessor and mutator methods for a
class. It is a broader concept of programming, not necessarily object-oriented
programming, that consists in minimizing the interdependence between modules
and it’s typically implemented through information hiding. Our software designs
the visible parts of our modules/classes constitute their public interface, and
this is exposed to the outside world, the rest of it should be hidden to the
naked eye. With encapsulation us as humans deal with complexity by defining
abstractions with public interfaces so that we are able to interact with them
and all of the code that lies beneath it is unnecessary in order for use it. Changes
are made in directional systems because internal implementation is encapsulated
and because of that, changes can we safely done without affecting it’ public
interface. By minimizing the impact of changes and independence of modules, we
can achieve proper levels of encapsulation in our software that can handle
change without breaking its users. Information hiding is important because it
decouples modules that compromise a system and it allows for them to be tested,
optimized, used, understood, and modified in isolation. This allows for other
modules to be developed in parallel and eases the burden of maintenance without
the fear of affecting other modules. Encapsulation is a desirable attribute
that allows for the evolution of APIs and as long as we respect public
interfaces of our abstractions, we are free to change whatever has been
encapsulated. Failing to define proper abstraction with proper levels of
encapsulation will end up causing difficulties when change happens. There is no
way to change the public interface of an abstraction without breaking its
users. Encapsulation is one of the tools we use that help us create good
abstractions, but no level of encapsulation is going to make bad abstraction

Source: https://dzone.com/articles/why-encapsulation-matters

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with WordPress.com
Get started
%d bloggers like this: