Today
I watched a tutorial on encapsulation. This is an extension of the public
private and protected tutorial. Explaining why we declare instance variables,
and methods private within a class. You want to declare a method private when
you are only going to use it within the class. In general try not to make
instance variables public unless they are constants. One reason we due this is
to reduce cross linkages, you don’t want one class getting entangled in another
class. Another thing the tutorial talked about is API documents. This is just
the documents of built in classes for java. For example String is a built in
class, meaning you don’t have to make a String class to create a String object
in java. The API document gives you information on everything about the class,
interfaces, instance variables, methods, constructers, etc. You will notice
that in the built in classes there aren’t many instance variables that are
public, except constants. The point of encapsulation is to define things
private as much as you can unless, you need to use them outside that class.
No comments:
Post a Comment