In this dice class I've told you the important of having our attributes as private, and using public methods to manipulate this data if we absolutely need to.
The problem is, we're testers, and we're not known for following rules particularly well ... so here it is ...
Make them public! What's the worst that could happen?
Remember when Simba was told everything the light touches was his kingdom. Except that shadowy place ... never go there?
Yeah - this ended up happening. Damn you Simba, you had one job!
So here's our revised class - I've streamlined it. And added those public attributes you asked for.
Cool - so let's run a test for it now!
I'm going to side with Uncle Scar on this ..."Simba what have you done?".
Here's the thing about private attributes. They can only be accessed and changed by class methods. If the attribute is vital, you can build recording around them to a log file to register changes. In our class above, I've put print commands for all the methods. If I had odd data, then I should check those methods with a fine tooth comb.
Now, here's the thing about public attributes. They can be accessed and changed anywhere. And on a large coding project, that's a frightening prospect.
It has the potential to be this ...
And sure, you have tools in your compiler and debugger which give you the equivalent of a metal detector and a powerful magnet. But you've still made more work for yourself than you need.
Most people who write code end up feeling like this ...
Whilst you're learning is a great place to go "I wonder why they say I need to". Learning is a great time to break rules, but also to learn some good habits.
This approach of only making public the methods that you really need to is called encapsulation, or data hiding. A bit like the ring of power in Lord Of The Rings, ask yourself "Is it secret? Is it safe?".
The big reveal
Yeah - well someone was nasty in the @Test method ...
The thing is, with the way you coded your DiceClass method, you didn't stop him from doing this!
You might notice how I'm blaming you dear reader for this, though I wrote it? Let me just finish with this ...
That code that you made me write can be found here.
Extension material
Google some articles and read up about encapsulation.
I have read your blog its very attractive and impressive. I like it your blog.
ReplyDeleteJava Training institute in velachery
I read encapsulation for java 14 whether it could be applied to the web version?
ReplyDeleteNicely explained. Here you described the well written article from your in-depth knowledge. Truly impressive and nice information
ReplyDeleteJava Training in Chennai Core Java Training in Chennai Core Java Training in Chennai
Java Online Training Java Online Training JavaEE Training in Chennai Java EE Training in Chennai
perfect explanation about java programming .its very useful.thanks for your valuable information. java training in chennai | java training in velachery
ReplyDeleteVery nice Information for Java languages, very nice informative and much effective as well.
ReplyDeleteJava Training in Chennai
very good information.it is very useful for java learners.keep rocks.thanks fpr sharing.
ReplyDeleteBest Java Training Institute in Chennai
Online casino games of Cambodia.
ReplyDeleteIBCbet Is a casino web site. The famous club of Cambodia. One of the most popular online casino games providers has become popular and popular among gamblers around the world. Playing online gambling games in this way allows all players to play online gambling games with only the Internet and play at any time desired
And important on the web page of the club. Online casinos also have a lot of online games to choose from, like playing casino games in general. Therefore, the online gambling games in each form is considered to be enjoyable and suitable for people who love and passionate about gambling. Therefore, playing online gambling is considered as an investment destination. little If players are thinking to play online gambling games, investment from our online casino, which is considered to be the best.
Because of the online gambling games on the site Poipet. Our casino allows players to create new experiences. The satisfaction of the risky and can also join in the joy and play online gambling games that want to play today at the site Sbobet
Really it was an awesome article...very interesting to read..You have provided an nice article....Thanks for sharing..
ReplyDeleteAre you looking for the best Java training institute in Chennai?
Come and learn with Aorta, the best java training institute in Chennai offering the best platform to learn and get the depth of Java
java training in chennai
java course in chennai
Our digital marketing course in Chennai is targeted at those who are desirous of taking advantage of career opportunities in digital marketing. Marketing professionals who are presently using traditional marketing to meet their business objectives. Start-ups, Entrepreneurs, Business Owners who desire to make use of online media to improve their business goals and objectives.
ReplyDeleteDigital Marketing Course in Chennai
Digital Marketing Training in Chennai
Online Digital Marketing Training
SEO Training in Chennai
I likable the posts and offbeat format you've got here! I’d wish many thanks for sharing your expertise and also the time it took to post!!
ReplyDeleteangularjs online Training
angularjs Training in marathahalli
angularjs interview questions and answers
angularjs Training in bangalore
angularjs Training in bangalore
angularjs online Training
Really great post, I simply unearthed your site and needed to say that I have truly appreciated perusing your blog entries. I want to say thanks for great sharing.
ReplyDeleteJava training in Bangalore | Java training in Electronic city
Java training in Bangalore | Java training in Marathahalli
Java training in Bangalore | Java training in Btm layout
Java training in Bangalore | Java training in Jaya nagar
Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information.
ReplyDeleterpa training in chennai
rpa training in bangalore
rpa course in bangalore
best rpa training in bangalore
rpa online training
Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
ReplyDeletepython course in pune
python course in chennai
python course in Bangalore
Really very nice blog information for this one and more technical skills are improve,i like that kind of post.
ReplyDeleteexcel advanced excel training in bangalore
Devops Training in Chennai
I am really happy with your blog because your article is very unique and powerful for new reader.
ReplyDeleteClick here:
selenium training in chennai | selenium course in chennai
selenium training in bangalore | selenium course in bangalore
selenium training in Pune | selenium course in pune | selenium class in pune
selenium training in Pune | selenium course in pune | selenium class in pune
selenium online training | selenium training online | online training on selenium
Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
ReplyDeleteData Science course in kalyan nagar | Data Science Course in Bangalore
Data Science course in OMR | Data Science Course in Chennai
Data Science course in chennai | Best Data Science training in chennai
Data science course in velachery | Data Science course in Chennai
Data science course in jaya nagar | Data Science course in Bangalore
Data Science interview questions and answers
Very useful and information content has been shared out here, Thanks for sharing it.
ReplyDeleteVisit Learn Digital Academy for more information on Digital marketing course in Bangalore.
nice blog . check out https://ayevainstitute.com/
ReplyDeleteHmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
ReplyDeleteAdvanced AWS Interview Questions And Answers, Top 250+AWS Interviews Questions and Answers 2018
Advanced AWS Interview questions and answers | Top 110 AWS Interview Question and Answers
Advanced AWS Training in Bangalore | Best Amazon Web Services Training in Bangalore
Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
ReplyDeleteAdvanced AWS Interview Questions And Answers, Top 250+AWS Interviews Questions and Answers 2018
Advanced AWS Interview questions and answers | Top 110 AWS Interview Question and Answers
Advanced AWS Training in Bangalore | Best Amazon Web Services Training in Bangalore
Howdy, would you mind letting me know which web host you’re utilizing? I’ve loaded your blog in 3 completely different web browsers, and I must say this blog loads a lot quicker than most. Can you suggest a good internet hosting provider at a reasonable price?
ReplyDeleteBest AWS Amazon Web Services Training in Chennai | Best AWS Training and Certification for Solution Architect in Chennai
Amazon Web Services Training in Tambaram, Chennai|Best AWS Training in Tambaram, Chennai
I accept there are numerous more pleasurable open doors ahead for people that took a gander at your site.we are providing ReactJs training in Chennai.
ReplyDeleteFor more details: ReactJs training in Velachery | ReactJs training in chennai
This is ansuperior writing service point that doesn't always sink in within the context of the classroom. In the first superior writing service paragraph you either hook the reader's interest or lose it. Of course your teacher, who's getting paid to teach you how to write an good essay,
ReplyDeletepython Online training in chennai
python Online training in bangalore
python interview question and answers
I recently came across your blog and have been reading along. I thought I would leave my first comment.
ReplyDeleteSelenium training in Chennai | Selenium training institute in Chennai | Selenium course in Chennai
Selenium training in Bangalore | Selenium training institute in Bangalore | Selenium course in Bangalore
Selenium interview questions and answers
Selenium training in Pune | Selenium training institute in Pune | Selenium course in Pune
Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
ReplyDeleterpa training in chennai
Best rpa training in bangalore
rpa course in bangalore
rpa training in marathahalli
rpa training in btm
best rpa training in chennai
Read all the information that i've given in above article. It'll give u the whole idea about it.
ReplyDeleteBest Devops online Training
Online DevOps Certification Course - Gangboard
Thank you for this post. Thats all I are able to say. You most absolutely have built this blog website into something speciel. You clearly know what you are working on, youve insured so many corners.thanks
ReplyDeleteData Science course in Chennai | Best Data Science course in Chennai
Data science course in bangalore | Best Data Science course in Bangalore
Data science course in pune | Data Science Course institute in Pune
Data science online course | Online Data Science certification course-Gangboard
Data Science Interview questions and answers
Data Science Tutorial
ReplyDeleteWhoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.
aws training in bangalore
RPA Training in bangalore
Python Training in bangalore
Selenium Training in bangalore
Hadoop Training in bangalore