---
title: "I misunderstanding Encapsulation rules in objective c."  
description: "I misunderstanding Encapsulation rules in objective c."  
author: "Tarun Kumar"  
published: 2015-08-20  
updated: 2015-08-21  
canonical: https://www.mindstick.com/forum/33422/i-misunderstanding-encapsulation-rules-in-objective-c  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# I misunderstanding Encapsulation rules in objective c.

I will [explain](https://www.mindstick.com/forum/157854/what-is-system-debugging-explain-some-system-debugging-tools-used-in-modern-computer-systems) my [question](https://www.mindstick.com/blog/23175/how-to-solve-neet-question-paper-in-less-time) from an example.

In .H [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp)//

```
@interface Employee:NSObject {    @private NSString *name;}    @property(nonatomic,retain) NSString *name;@end
```

in .M file//

```
@implementation {    @synthesize name; }
```

In this [scenario](https://yourviews.mindstick.com/view/81221/sports-will-change-the-education-scenario) when i [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) the [name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide) [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) within another [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) , like myEmp.Name = @"John"; it doesn't raise any issue. Does this according to the [encapsulation](https://www.mindstick.com/articles/12229/encapsulation-and-access-specifier) [rules](https://www.mindstick.com/articles/43901/blackjack-rules) or am I misunderstanding?

## Replies

### Reply by Anonymous User

In Objective-C, only an instance method of object can access an instance variable. There is no way for an external object to access the instance variables of an object directly. The @private is only relevant to inheritance.

To make the variables accessable there are properties. A property defines a method, and methods on Objective-C are all public. There is no way in Objective-C do define private methods, you can only "hide" them by declaring them somewhere else than the public .h file (e.g. inside the .m file via @interface Employee() which declares an anonymous section).


---

Original Source: https://www.mindstick.com/forum/33422/i-misunderstanding-encapsulation-rules-in-objective-c

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
