Hello my friends, I have two questions
Q1/
If we make field private and setter and getter for it, does that mean we are applying the Encapsulation principle?.
Q2/
If we make the method private, that means we are applying the Abstaction principle?.
Q1 Yes I think so. By making the field private you are hiding/encapsulating the internal workings of your class.
Q2 I think this is also encapsulation, not abstraction. One example of abstraction is the File
class in Java. It’s not the files themselves, but it gives you a way, an interface, for working with files. It has methods that allow you to createNewFile
or delete
a file, without worrying about all the underlying details of how the file is actually created or deleted. In other words, it abstracts all of the complicated details away and gives you a simplified way to do things.