Solved

Interview Question?

Posted on 2006-11-10
5
443 Views
Last Modified: 2010-04-16
What is your definition of encapsulation?
0
Comment
Question by:mathieu_cupryk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 17920872
The hinding of information or internal implementation code/logic behind a public API/Interface.
0
 
LVL 3

Assisted Solution

by:bromose
bromose earned 250 total points
ID: 17921388
Encapsulation means protecting the information carryed in an object from beeing unwanted manipulatet. This means that your fields in your class must be private, and the only should be avalible to "the public" using properties og methods as "accessors" and "mutators". This gives your object full control of the business logic associatet with manipuilating the fields (fx. can a bank account ballance be negative ? - this must be controled by the account object mutator (set) method).

Hope this will cast som light (sorry for my English)

Regards, Kaj Bromose
0
 

Author Comment

by:mathieu_cupryk
ID: 17922267
hi Bro,

Can you describe to me "accessors" and "mutators" a little bit more in detail.
0
 
LVL 15

Accepted Solution

by:
ozymandias earned 250 total points
ID: 17922516
Accessors and Mutators are methods that change the properties of an object rather than allowing those properties to be acessed/modified directly.
Basically you are placing validating logic between the values stored in an object and the outside world.
An accessor is a method that retrieves (or gets) a value and a mutator is a method that changes (or sets) a value.

In C# we have object members that look like properties but that actually have logic :

public int MyIntValue{
    get{// accesssor logic}
    set{// mutator logic}
}

The compiler actualy generates hidden methods called __getMyIntValue and __setMyIntValue but this is not apparent in the public interface of the obejct.
0
 
LVL 3

Expert Comment

by:bromose
ID: 17922569
Thank You to ozymandias for the answer. I agree on the comments of ozymandias. However please note the difference between the use of properties and methoeds. Propertiers are uses for "simple" acces to fields - accessors and mutators (the attributes of Your UML diagram). Methoeds on the other hand is uses to implementes be behavior of Your objects - the methoeds described in your UML diagram, wich came from the analysis of the dynamics in Your Use Cases.

Regards,
Kaj Bromose
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question