I have just learned how to mask a base class member (using new) but am missing the point as to why I would want to do that. Does masking provide us with a certain level of protection as is the case in using encapsulation? Please advise.
...
I have an Email object with two properties, label and value. System user need to verify their email before they can use it in the system. The verification process is very simple:
Set an activation code for the email
Send an email with the activation code to verify that the email is valid
The email object looks like the following:
...
I'm talking specifically about the public, private and protected keywords that can apply to properties and methods. I've looked everywhere and I know what they do and how to use them, but don't see how they would be practical when programming. Could somebody explain or give an example?
...
How can we encapsulate a message with any protocol header.Message can be char * or a pointer to memory field (void *).
Actually i want to do is :
message --> add protocol header(e.g udp)
|udp header + message |
struct UdpHeader {
int Sport,Dport,chksum,size;
}
void sendMsg(void *msg,int sport,int dport,int size)
{
Udp...
Given a C API to a library controlling sessions that owns items, what is the best design to encapsulate the C API into RAII C++ classes?
The C API looks like:
HANDLE OpenSession(STRING sessionID);
void CloseSession(HANDLE hSession);
HANDLE OpenItem(HANDLE hSession, STRING itemID);
void CloseItem(HANDLE hItem);
Plus other functions th...
I'm a new programmer, so please forgive any dumbness of this question but can anyone please tell me how the folowing code is encapsulating private data-
public class SomeClass
{
private int age;
public int Age
{
get { return age; }
set { age = value; }
}
public SomeClass(int age)
{
this....
Hi guys,
currently I am thinking about data encapsulation in C# and I am a little bit confused.
Years ago, when I started to learn programing with C++, my professor told me:
- "Create a class and hide it data members, so it can't be manipulated directly from outside"
Example:
You are parsing an XML file and store the parsed data into ...
I would like to know in what scenarios you use encapsulation. The purpose of this question is collaborative. So feel free to share your own experience when the subject is encapsulation.
Some scenarios:
Calculated property
public class Order {
private List<ListItem> listItems = new ArrayList<ListItem>();
public double getTota...
In visual studio you can set accessors by using the encapsulate field refactoring operation on a declaration (Ctrl + E,R shortcut).
Is it possible to generate (using the default settings) the accessors of several field at once ?
Having :
private int one;
private int two;
//etc
and generating :
public int One
{
get { return one;...
If I have a class that includes a file with a constant like so:
define("FOO", "bar");
Is there a way to make the class include the file with encapsulation so if I use the class somewhere that already has a FOO constant defined it won't break?
...
I am building a game and have several groups of namespaces. One is called "Engine" the other called "Game". There are several functions and variables that I only want Engine to be able to see. What do I need to do to hide certain functions (not whole classes) from the Game namespace.
...
I'm writing a C# library to wrap a Win32 API (the waveOut... family of functions), and have reached a point where I'm unsure how to manage the interaction between different parts of my code without breaking encapsulation. So far, I have a setup like this:
public class AudioDevice
{
...
private WaveOutSafeHandle hWaveOut;
......
I have a problem that is quite common in the code that I am writing at the moment whereby I want to have an integer that can only exist inside a certain range where the range is [start, end). Basically I want to be able to do something like the following:
cyclic_int ci(4, 8);
ci = 4;
assert(ci == 4);
ci += 3;
assert(ci == 7);
ci += 2;
...
How can i perform dependency injection without breaking encapsulation?
Using a Dependency Injection example from Wikipedia:
public Car {
public float getSpeed();
}
Note: Other methods and properties (e.g. PushBrake(), PushGas(),
SetWheelPosition() ) omitted for
clarity
This works well; you don't know how my object implem...
Currently I'm writing a little webserver and I create a new Thread for every request the server gets.
Basically it's like this:
public class MyController
{
public void ProcessRequest(object contextObject)
{
HttpListenerContext context = (HttpListenerContext)contextObject;
// handle request
if (someCondition()...
Does Encapsulation is information Hiding or it leads to information hiding??
As we say that Encapsulation binds data and functions in a single entity thus it provides us control over data flow and we can access the data of an entity only through some well defined functions. So when we say that Encapsulation leads to abstraction or infor...
I was wondering how one can conditionally hide data in class.
For instance , lets say I have a class called Car which has three fields :
Engine , MeterReading and Mileage.
I have three other entities called : Driver , Mechanic and Passenger.
Now what I want is that :
A Driver should only be able to access Mileage ( and not Engine an...
Given two classes in your LINQ to SQL .dbml file with the following properies.
Customer
CustomerId
FirstName
LastName
AddressId
Address
AddressId
Street
City
State
Zip
You could construct a LINQ query such as the following.
using(var db = new MyDataContext())
{
results = db.Customers
....
I am sortof using a repository pattern to extract information from a database. I have two classes, report and reportRepository.
The trouble I have is that since reportReposity has to fill in all the details for the report object, all the members in the report have to be publicly accessible.
Is there a way so that I can ensure that onl...
I'm pretty new to Javascript, as my SO profile will attest.
I've just been reading up on a few tutorials and come across something I don't totally understand in regards to Object Orientation and Encapsulation when applied with Javascript.
The tutorial stated that Javascript objects can be declared like this:
var myCustomObject = new O...