Solved

Interview Question?

Posted on 2006-11-10
5
419 Views
Last Modified: 2010-04-16
What is your definition of encapsulation?
0
Comment
Question by:mathieu_cupryk
  • 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error in JQuery 5 52
Diagnostics with Net and Net.Sockets 2 28
List<PaisEntity> - show some 1 24
Release Dynamically Allocated Memory in C# 3 25
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

777 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