?
Solved

Interview Question?

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

807 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