I am studying about OOP concepts. As I understood from the documents I have read, I wrote an example program for encapsulation concept in OOP. I pasted my code below. Is my concept about encapsulation is correct ?.

Re: Encapsulation in OOP?

Posted on 6 years ago

From an OO perspective, your ShowDetails method is doing two very different things.

Creating a string that represents the object

Outputting the string to the HttpResponse.

Now The first task does belong to the class Student, you need to know what an Student is to be able to create a string that is representative of the object. In fact in .net this is such a common thing, there is in fact a "overridable" or "virtual" function called Object.ToString().

The second task has absolutely nothing to do with the class Student, and A LOT to do with strings and HttpResponses (and in this case how we get the HttpResponse, which is to get it from the HttpContext, which means we MUST be on a webserver in a HttpRequest). With all these assumptions, it is extremely unsafe in an all purpose "data" or "domain" class.