If I wrote an operator == for class Foo (in C++), what happens, exactly? Does it compare each data member against each other?
class Foo
{
private:
int bar;
public:
bool operator==(const Foo other&)
{
return *this == other; //what?
//is this the same as bar == bar?
}
}
...
After careful reading the facts about singletons (the code smell, not the pattern) I wonder:
How can I refactor my code to get rid of them?
Despite almost everyone agreeing that bad singletons are, well, bad, I could not found any practical advice on how to replace them. Either it's very trivial or very hard.
There are some ways I c...
Hi all,
We have the following Database design.
As you can see, there is non normalized between the main tables ("ACCOUNTS" and "CONTACTS") with "NOTES".
How we can get a collection of "Notes" for the 2 main tables based on this DB design within NHibernate? We don't have the option to modify the existing DB design.
ACCOUNTS (consider...
I am developing a project that calculates various factors for a configuration of components.
The configuration is set/changed by the user at runtime. I have a Component base class and all configuration items are derived from it.
The information for each component is retrieved from data storage as and when it is required.
So that the sto...
Hi,
I have a list of base objects (RTUDevice) and want to iterate through and convert each to a derived object (actually a derived of a derived RTDSensor) , however the downcasting is throwing an error.
public RTUDevice(int id)
{
_id = id;
}
public class RTDDevice : RTUDevice
{
public RTDDevice(int id)
: base(id)
{...
I am confused about abstraction and encapsulation.What i feel is that class is encapsulation as it encapsulates data and behaviour,while interface is abstraction.Please comment
...
Hi All, I'm working on a database factory pattern for an application which should support Sql Server and Oracle. I've an abstract classes with all the Sql Queries for the application. I've implemented the abstract class in two classes: SqlServerClass and OracleClass. Based on the connection string defined in the configuration file, the a...
Is it possible to achieve the following, using jQuery:
I'd like to create two different objects that have different functions with the same name.
var item = new foo();
item.doSomething();
var item2 = new bar();
item2.doSomething();
Furthermore, I'd like to be able to use the created items as "regular" jQuery objects - for example, t...
Possible Duplicate:
Can you write object oriented code in C?
I am writing a large application in C and have heard that prior to the advent of C++ programmers used to implement the "Object Oriented" pattern in C. My question is what is the usual form this pattern takes? and how would I go about implementing such an OOP pattern in...
Class hierarchies and constructors are related. Parameters from a child class need to be passed to their parent.
So, in Python, we end up with something like this:
class Parent(object):
def __init__(self, a, b, c, ka=None, kb=None, kc=None):
# do something with a, b, c, ka, kb, kc
class Child(Parent):
def __init__(sel...
Is it possible to keep all my database related configuration (hostnames, usernames, passwords, and databases) as well as the function to connect to and select the correct database in a seperate class?
I tried something like this:
class Database
{
var $config = array(
'username' => 'someuser',
'password' => 'somepass...
I've created a Display object that contains the header, sidebar and footer:
class Display {
protected $framework;
public $mysql;
public function __construct() {
$this->mysql = new MySQL();
$this->framework .= $this->header();
$this->framework .= $this->body();
$this->framework .= $this->sideba...
I would like to make use of few methods from couple of my old tested classes into my new class that I am building. Unfortunately, C# does not support multiple inheritance. How do I reuse code from these old classes? Do I just create them as member objects? or Do I have any other options?
...
Does anyone have any examples of the Blackboard concept from p.165 of 'The Pragmatic Programmer'?
I want to have several small sub-systems (DLLs and EXEs) mostly independent of each other. There are some assemblies that will be used by all EXEs. These assemblies will nearly all use the same database. Rather than using interfaces for ...
I have a class called TASKS.
I want one property of the class to be dynamic enough to handle a structure change in the strong type. for example....
Class MyClass
{
public [mychangingProperty] - can be any strongly typed class....
}
How is this possible?
...
I realize the code below is not the most efficient way of grabbing elements, but for the sake of an example...
$('.myFirstClass').each(function(i){
// Here is the first 'THIS' occurrence
$(this).find('.mySecondClass').each(function(j){
// Here is the second 'THIS' occurrence
// How do i access the first occurrence from...
PHP has an in_array function for checking if a particular value exists in an native array/collection. I'm looking for an equivalent function/method for ArrayObject, but none of the methods appear to duplicate this functionality.
I know I could cast the ArrayObject as an (array) and use it in in_array. I also know I could manually iter...
There's this dichotomy in the way we can create classes in f# which really bothers me. I can create classes using either an implicit format or an explicit one. But some of the features that I want are only available for use with the implicit format and some are only available for use with the explicit format.
For example:
I can't use ...
I bump into this from time to time during class design... when I have several properties of the same type in the object. Take few examples:
User has several addresses. We can do
IDictionary<string, Address> Addresses; // Addresses["BusinessAddress"];
or
Address BusinessAddress;
Address ShippingAddress;
Product has related product...
I am trying to get my head around applying template programming (and at some future point, template metaprogramming) to real-world scenarios. One problem I am finding is that C++ Templates and Polymorphism don't always play together the way I want.
My question is if the way I'm trying to apply template programming is improper (and I sho...