In the last lesson VSA how setters and getters can be used to prevent direct access of of us. 2
But it's not just variables. 3
We also want to be careful about what methods and classes we are exposed to external code that is there 4
can be tight coupling to even methods and classes. 5
So we will not look at another effective July time that gives some more advice on how we can go about 6
hiding information. 7
The item is item 13 and it says minimize the accessibility of classes and members. 8
Let's review what it has to say and it's going to be a sharp lesson when it comes to designing class 9
members here is a general solution from the item just carefully design a minimal public API of your 10
class so once you have an idea of the variables on matters that go into your class just carefully look 11
at all the class members and see which of them will really be needed by the clangor and just make them 12
public all that how many members should be made private. 13
Only if an class in the same package really needs access to a private member then you would convert 14
it to the default access and same holds for converting something into public member. 15
Now if you find yourself doing such conversions often then you may want to re-examine your design probably 16
structuring your classes in a different way. 17
Could be a better solution. 18
Come into classes or interfaces vino that they can hire only public publico default access lever's surfer 19
class or interface can have default as accessible then liquored have default access level because once 20
it is public you would be obligated to support it for whatever. 21
So basically give the client code access to only what they need. 22
Match within your package if a class is used by only one other class then consider making that class 23
a private master class within the class that uses it. 24
Mr. Crossus will be introduced much later but it is simply a class that an underclass like in the strict 25
follow up it simply exists to serve its enclosing class so that's about information hiding. 26
So we software design principles that use access modifiers to achieve information hiding information 27
hearting helps in building well-designed design software which then loosely coupled components as you 28
can see the principles are pretty straightforward. 29
Generally I think double uppers do use accessor methods for class members. 30
However when it comes to classes they don't follow the advice that we see here. 31
They usually make the classes public all the time. 32
It may not be an issue at all if your code is never used outside your company but if you're writing 33
code that will be used by public or your partners then you must follow the advice given in this lesson 34
just know that this advice comes from Joshua ablock who has written tons of July API called on so it 35
would serve us well if you take his advice seriously Also one last comment I would like to make is sometimes 36
people refer to encapsulation as information hiding in our case they're introduced us separate concepts 37
and that is very widely acceptable as we look at them so just want to highlight that sometimes you may 38
come across people using the term encapsulation for information hiding. 39
But you know what that mean in fact the supplementary notes includes a link to a great article on this 40
topic and you can check it out in your free time. 41
And that's about it. 42
Thank you