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

image with no caption

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.

image with no caption

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? ...

Get Head First C#, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.