Click here to Skip to main content
15,913,467 members
Home / Discussions / C#
   

C#

 
AnswerRe: Help with PictureBox.image updating from Webcam capture Pin
Luc Pattyn16-Jan-10 10:03
sitebuilderLuc Pattyn16-Jan-10 10:03 
GeneralRe: Help with PictureBox.image updating from Webcam capture Pin
shutupsquare16-Jan-10 10:17
shutupsquare16-Jan-10 10:17 
AnswerRe: Help with PictureBox.image updating from Webcam capture Pin
shutupsquare16-Jan-10 10:08
shutupsquare16-Jan-10 10:08 
GeneralRe: Help with PictureBox.image updating from Webcam capture Pin
Luc Pattyn16-Jan-10 11:05
sitebuilderLuc Pattyn16-Jan-10 11:05 
GeneralRe: Help with PictureBox.image updating from Webcam capture Pin
shutupsquare16-Jan-10 12:56
shutupsquare16-Jan-10 12:56 
GeneralRe: Help with PictureBox.image updating from Webcam capture Pin
Luc Pattyn16-Jan-10 13:03
sitebuilderLuc Pattyn16-Jan-10 13:03 
Questionencapsulation understanding problems Pin
binn01916-Jan-10 6:41
binn01916-Jan-10 6:41 
AnswerRe: encapsulation understanding problems PinPopular
Jimmanuel16-Jan-10 7:11
Jimmanuel16-Jan-10 7:11 
First, C# has Properties that replace explicit getters and setters:
public string SchoolName
{
    get { return name; }
    set { name = value; }
}

and then instead of calling
d.SetSchool("Alan");
Console.WriteLine("The School is :" + d.GetSchool());

you just do
d.SchoolName = "Alan";
Console.WriteLine("The School is :" + d.SchoolName);


Second, the reason to do this is to separate the interface of the class from the implementation of the class. The interface is what is presented to other classes when they use your class, in other words the interface is what the class can do. The implementation of the class is the internal stuff that other classes don't need to know about, it's how a class does what it does. To maximize code re-usability classes shouldn't know or care about the how, all they need to know is the what.

This goes along with:
binn019 wrote:
protect the data by outside world

This means that you don't allow other classes to access any stuff that they don't need to. Your School class stores the name of the school. Do other objects need to know how it stores that? No, they only need to know that it does store it. All other classes need to know is that they set the value d.SchoolName to something to change the name and use that same value to retrieve the name later. Internally it's up to School to store it however it makes sense. Right now it's a string but what if later on you want to change it? If you use proper encapsulation then you can change how School stores the name without affecting any other class, but what if you want to change the variable testing? Then you have to go through all of the files in your code that use that variable and update them as well. This is the essence of encapsulation.

Example: The way things are right now you can change the variable name to an int without breaking anything:
public class School
{
    private int name;

    public string testing;
    // Accessor.
    public string GetSchool()
    {
        return name.ToString();
    }
    // Mutator.
    public void SetSchool(string a)
    {
        if (!int.TryParse(a, out name))
        {
            name=0;
        }
    }
}

Why? who care. That's not relevant; what is relevant is that you can change name to anything you want without having to change any of the code in main because name is properly encapsulated. You cannot do the same thing with variable. If you change it to an int then you also have to change the code in main to reflect that change.

Badger | [badger,badger,badger,badger...]

GeneralRe: encapsulation understanding problems Pin
binn01924-Jan-10 0:02
binn01924-Jan-10 0:02 
QuestionNeed help with drawing circles on mouse click event in pictureBox Pin
Midex16-Jan-10 5:49
Midex16-Jan-10 5:49 
AnswerRe: Need help with drawing circles on mouse click event in pictureBox Pin
Luc Pattyn16-Jan-10 6:13
sitebuilderLuc Pattyn16-Jan-10 6:13 
AnswerRe: Need help with drawing circles on mouse click event in pictureBox Pin
Dan Mos16-Jan-10 7:53
Dan Mos16-Jan-10 7:53 
QuestionBackgroundWorker with anonymous methods ? Pin
Mohammad Dayyan16-Jan-10 4:06
Mohammad Dayyan16-Jan-10 4:06 
AnswerRe: BackgroundWorker with anonymous methods ? Pin
Nicholas Butler16-Jan-10 4:59
sitebuilderNicholas Butler16-Jan-10 4:59 
GeneralRe: BackgroundWorker with anonymous methods ? Pin
Mohammad Dayyan16-Jan-10 6:58
Mohammad Dayyan16-Jan-10 6:58 
QuestionHolding data in memory Pin
Bardy8516-Jan-10 0:22
Bardy8516-Jan-10 0:22 
AnswerRe: Holding data in memory Pin
OriginalGriff16-Jan-10 1:01
mveOriginalGriff16-Jan-10 1:01 
GeneralRe: Holding data in memory Pin
Bardy8516-Jan-10 1:16
Bardy8516-Jan-10 1:16 
GeneralRe: Holding data in memory Pin
N a v a n e e t h16-Jan-10 6:05
N a v a n e e t h16-Jan-10 6:05 
GeneralRe: Holding data in memory Pin
Dan Mos16-Jan-10 7:21
Dan Mos16-Jan-10 7:21 
GeneralRe: Holding data in memory Pin
Bardy8516-Jan-10 9:21
Bardy8516-Jan-10 9:21 
GeneralRe: Holding data in memory Pin
Luc Pattyn16-Jan-10 10:05
sitebuilderLuc Pattyn16-Jan-10 10:05 
GeneralRe: Holding data in memory Pin
Bardy8516-Jan-10 10:56
Bardy8516-Jan-10 10:56 
GeneralRe: Holding data in memory [modified] Pin
Dan Mos16-Jan-10 11:01
Dan Mos16-Jan-10 11:01 
GeneralRe: Holding data in memory Pin
Bardy8516-Jan-10 9:28
Bardy8516-Jan-10 9:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.