Solved

Interview Question?

Posted on 2006-11-10
5
390 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
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!
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now