I'm working on modeling a business domain object in a class and am wondering what would be the best way to properly encapsulate private fields that only apply to a few methods.
When I started, my code originally looked like this:
public class DiscountEngine
{
public Cart As Cart { get; set;}
public Discount As Discount { get; s...
I was going through an article on event bubbling in asp.net and came to know that although it is possible to subscribe to the click event of a user control's button from the containing page, "doing so would break some of the object oriented rules of encapsulation". A better idea is to publish an event in the user control to allow any int...
Dear all,
We have a dll file; let's say X.DLL.
We are now writing another DLL, let's say "A.DLL" that uses some (very few) of the functions of X.DLL. We have no access to source code of X.DLL. Also, we don't want to give our clients X.DLL along with A.DLL.
Instead, we want to encapsulate X.DLL within A.DLL, so that distributing A.DLL ...
Let's say I'm building a library to spork quuxes in C.
Quuxes need two state variables to be sporked successfully:
static int quux_state;
static char* quux_address;
/* function to spork quuxes found in a file,
reads a line from the file each time it's called. */
void spork_quux(FILE*);
If I store that data as global variables, o...
I have a public class, MainObject that is in a class library (dll), for this example we will call it BaseLibrary.
I have a higher level class library that references the BaseLibrary to gain access to it's members. We will call this one DeviceLibrary.
I then have a Windows Forms Project, DeviceControl, in which I have added a reference ...
Hi, For some time now I am trying to figure out how I can refactor some of my code to reduce redundancy throughout my application. I am just learning the basics of OOP and can create simple classes and methods but my knowledge is limited in terms of practical applicability. The following bit of code illustrates my frustration:
#region D...
Possible Duplicate:
clean C++ granular friend equivalent? (Answer: Attorney-Client Idiom)
I've wanted this a couple times and haven't been able to come up with a decent way to do it.
Say I've got a member function in class A. I want to be able to call that function from an unrelated class B, but not be generally callable. You...
I'm wondering whether an object asking a question to another object that indirectly holds it is "bad" design. For example...
Requirements:
Character (an object) moves on a grid. When it tries to move to another spot, it needs to know whether that spot is already occupied by something that blocks it, or if that part of the grid is comple...
I have a view, which wants to consume information from a presentation model. This model contains among other things, a collection of ActiveRecord objects.
I would like to not expose the entire collection to the models consumers, but instead wish to only expose the 'data' part.
I expect that I can write a method to create a data-only co...
Yes, you can set a property name by setName and get it by getName.
But what about property like this in C#:
int Name{
get{return name;}
set{name = value;}
}
or
Name{get; set;}
(auto property)
I wonder if such thing exists in Scala. Googling around without any signals.
...
Hello everyone,
Please can somebody explain to me the main differences between the principles of encapsulation and abstraction in objected-oriented programming (if possible with examples).
Thanks in advance.
...
I'm working on a method that needs to repeat a small operation at different spots, but the code to be repeated should be private to the method. The obvious solution is a nested function. Whatever I try however, the C# compiler barfs at me.
Something roughly equal to this Perl snippet:
my $method = sub {
$helper_func = sub { code to...
Background - I have a model, say Door, that has a state of open or closed. I encapsulate the behaviour of opening the door in a method #open on each instance (And I also have a #close equivalent).
But what's the best way to expose this in a RESTful way? What should my route be?
It is an UPDATE to Door instance, but what should I UPDATE...
I am trying to write and implement a simple node/tree interface in PHP. Something along these lines:
interface node
{
public function setParent(node $node); // can be null
public function removeChild(node $node); // should not be null
public function addChild(node $node); // should not be null
}
The implementation details...
I'm creating a little puzzle game just as a hobby project but the project has now reached a point that there is quite a lot of code (about 1500 lines). Although I've tried to prevent it, the code has become messy. I definitely want to clean up the code and make it more maintainable and readable while I still can.
There are 3 classes han...
Hi,
I have a base class:
class Message
And two deriving classes:
class SimpleMessage : Message
class ComplexMesssage : Message
These types are used in another part of the code as such:
void ProcessSimpleMessage(SimpleMessage m)
void ProcessComplexMessage(ComplexMessage m)
These methods are not inside the class Message, as the p...
Possible Duplicate:
Public Data members vs Getters, Setters
In what cases should public fields be used, instead of properties or getter and setter methods (where there is no support for properties)? Where exactly is their use recommended, and why, or, if it is not, why are they still allowed as a language feature? After all, t...
How does PPP behave when it comes to authentication or communication between two routers?
If both routers' serial interfaces include the command "encapsulation ppp" and nothing else, does it still require password? Or "ppp authentication PAP/CHAP" needs to be entered also? In any case, what password would PPP use to authenticate assumin...
Short question
I have one C++ domain model. It has some methods used by the internal API as well as other public methods. I don't want to expose those API methods. I'm thinking of using the proxy pattern to hide those methods. Do you think this is a good idea? Is there some design pattern to achieve this?
Long example
Let's say there'...
I've started learning Objective-C a few weeks ago and I still don't understand how to manage the encapsulation of a class correctly. What is the best way to declare a private member variable in a class?
It seems that setting the right getter/setter for your member variable with "@property" is the right way to go, more than just declarin...