Chapter 5. Encapsulation: Keep your privates... Private

Ever wished for a little more privacy?
Sometimes your objects feel the same way. Just like you don’t want anybody you don’t trust reading your journal or paging through your bank statements, good objects don’t let other objects go poking around their fields. In this chapter, you’re going to learn about the power of encapsulation. You’ll make your object’s data private, and add methods to protect how that data is accessed.
Kathleen is an event planner
She’s been planning dinner parties for her clients and she’s doing really well. But lately she’s been having a hard time responding to clients fast enough with an estimate for her services.

When a new client calls Kathleen to do a party, she needs to find out the number of guests, what kind of drinks to serve, and what decorations she should buy. Then she uses a pretty complicated calculation to figure out the total cost, based on a flow chart she’s been using for years. The bad news is that it takes her a long time to work through her chart, and while she’s estimating, her potential clients are checking out other event planners.
It’s up to you to build her a C#-driven event estimator and save her business. Imagine the party she’ll throw you when you succeed!
What does the estimator do? ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access