?
Solved

Interview Question?

Posted on 2006-11-10
5
Medium Priority
?
468 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 1000 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 1000 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

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

770 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