Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
December 10, 2018, 03:54:22 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: Understanding Data Encapsulation  (Read 7273 times)
barrettlikespizza
Newbie
*
Posts: 17


The secret of getting ahead is getting started.


WWW
« on: February 05, 2015, 02:16:30 AM »

My question pertains to this part of the book after Program 3.3:

"...(Data Encapsulation) enables someone writing class definitions to extend and modify the class definitions, without worrying about whether programmers (that is, users of the class) are tinkering with the internal details of the class."

So my first question is What is a class definition?

I understand that a "Fraction" is a class we've created.
"NSObject" is the parent class of Fraction (NSObject is probably the parent class of a lot of classes).
But what is a class definition?

Secondly, what does the author mean by "without worrying about whether programmers are tinkering with the internal details of the class."?

The only answer I can think of to my above question would be this:

"Data encapsulation means that details about a class are 'hidden' or 'tucked away' inside the implementation section. So if you work at a tech company in Northern California, and your only job is to create classes, you can be sure the guy in the next cubicle can't manipulate your classes. He just writes the program section, which sends messages to objects from classes that you've created."

Does any of that make sense? And if so, is it accurate? If not, what points am I missing?

Thank you for your help!
« Last Edit: February 05, 2015, 02:24:03 AM by barrettlikespizza » Logged
BrianLawson
Sr. Member
****
Posts: 262


Email
« Reply #1 on: February 05, 2015, 07:07:38 AM »

You've got it. A class definition is the implementation of a class.
Logged
barrettlikespizza
Newbie
*
Posts: 17


The secret of getting ahead is getting started.


WWW
« Reply #2 on: February 05, 2015, 11:35:50 AM »

BrianLawson, thank you for answering my question so quickly!

I feel like I've mostly got it now.

But one thing I'm wondering about is this:

The whole idea of data encapsulation is to hide things from programmers.

But what would stop a programmer from simply editing the @implementation section?

Or is the author talking more about something like main.h where we can't see what's inside main's implementation section?
Logged
BrianLawson
Sr. Member
****
Posts: 262


Email
« Reply #3 on: February 05, 2015, 01:42:23 PM »

If you are writing your own class definitions you can change them however you please, only proper programming practices is what keeps one writing proper code.

If you are working in a production shop, odds are that someone else may be writing the classes and you don't have access to the .m files, only the header files for implementing your code that makes use of those classes.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents ゥ 2009 classroomM.com. All rights reserved.