Possible Duplicate:
redefine a non-virtual function in C++
the rule of the thumb is "you should not override the non virtual member functions of the base class"
now if i override the the non virtual member functions of the base class what are the dangers please explain with examples.
...
There are two classes:A and B.
And I need to implement a function whoViewed,
I have two options,make it an member function of A and B.Which smells a little duplicate.
Another choice is to make it a separate class:Viewer,but it's more abstract.
If you were me,which way will you choose?
To make it more general:
what will you do when ...
I have a bit of problem with this. I have a class A which instantiates an object of B and then B which instantiates an object of A. Is this at all possible? I tried adding this in the headers of each
#ifndef A
#define A
class a...
#endif
but if keeps me in an infinite header loop which it reaches the maximum header includes, so obvi...
I'm creating an application for the iPhone in which I need to transfer information from variables between views/classes. What is the best way to do this (without utilizing CoreData/persistent storage)?
...
I've seen a lot of uses of the const keyword put after functions in classes, so i wanted to know what was it about. I read up smth at here: http://duramecho.com/ComputerInformation/WhyHowCppConst.html .
It says that const is used because the function "can attempt to alter any member variables in the object" . If this is true, then shoul...
Hi all,
I've a question regarding enforcing a business rule via a specification pattern. Consider the following example:
public class Parent
{
private ICollection<Child> children;
public ReadOnlyCollection Children { get; }
public void AddChild(Child child)
{
child.Parent = this;
children.Add(child);
...
Our team is fairly new to DDD, and are trying to implement some of the concepts in our current project. One question that has come up is whether to put methods into entity objects, or service objects.
Some team members feel that entities should only hold values and all functionality should be contained in services. Others feel this ...
Hi,
In the Factory Method Design pattern of GoF, I can see that there is no parameter accepted by the FactoryMethod() method. My understanding is that the FactoryMethod should be passed a parameter that will be used in the switch case and then based upon the value in the switch case, different class objects are instantiated and returned...
Heyho,
There´s a question in my mind for some time now, which hopefully can be cleared quickly by some of you:
I am a big fan of MVC, ASP.Net Mvc in my case.
What I have noticed is the hype about interfaces. Every video, tutorial and book seems to solve any kind of abstraction with interfaces. I have adapted these patterns, understoo...
I am on the quest to be a good OO-developer. OO intrigues me, because I understand the patterns, know why composition gives you more flexibility then inheritance, and more of such wisdom. However, I came to the conclusion that I know how to implement a factory of a singleton, but that I do not know how to come up with a robust OO design....
How can I hide the parent class property in child class.
Where parent class has a property called "Parent", where I don't want to use that in child class. How can I remove or hide that.
...
Somebody please shed some light on how Add method is implemented for
(how Add method is implemented for List in c#)
listobject.Add();
where List<User> listobject= new List<User>() is the declaration for the object.
I know that using List we can perform many operations on a fly and that too with type safety, but what I wonder is how ...
Hi,
I have a problem regarding assign session variable to class variable while initialize the class variable.
Check my below code
<?php
class ModifyProfile
{
var $userType=$_SESSION['wb_user_type'];
var $tablename=WB_CUSTOMER_TABLE;
var $primarykey="nCustomerID";
}
?>
When i run the above code by creating this class o...
I am experimenting with PHP OOP
what i'm trying to find out is, Is it possible to access a object instance from withing a object that was created in this object instance?
sounds confusing, so here is a example:
contents of index
class mainclass {
var $data;
function __construct($data){
$this->data = $...
I am new to OOP and have some questions.
Why can't methods declared in an interface have modifiers(public,private etc).
In this code:
class Program
{
static void Main(string[] args)
{
X ob = new Y();
ob.add(4, 5);
Z ob1 = new Y();
ob1.mull(2, 3);
Console.Read();
}
}
public interf...
I know it's not an easy question to answer, but a client of mine came to me and asked if I'd be interested in a "get paid to learn objective-c and iPhone development" project before they go to another developer.
I come from a a web background and my primary languages is PHP. I consider myself to be at expert level. I develop using Zend...
I have read from the Wikipedia that:
“References cannot be null, whereas pointers can; every reference refers to some object, although it may or may not be valid.”
But I don’t believe because of following code look at it compiler gives no error:
class person
{
public:
virtual void setage()=0;
};
main()
{
person *object=NULL;
perso...
I'm trying to figure out when it would be appropriate for a class to have both static and non-static functions. AKA:
$obj = new ClassA;
$obj->doOOPStuff();
$something = ClassA::doStaticStuff();
Note: This example is done in PHP, however the question is language agnostic .
It seems that if you have a class that is meant to be instant...
Is it possible to remove a decorator from an object?
Say I have the following code:
abstract class Item
{
decimal cost();
}
class Coffee : Item
{
decimal cost()
{ // some stuff }
}
abstract class CoffeeDecorator : Item
{
Item decoratedItem;
}
class Mocha : CoffeeDecorator
{
Item decoratedItem;
public Mocha(...
I know it can't be done, well I hope it can't or my Google skills have failed me.
But my annoyance is beyond that now, I have abandoned all hope of ever being able to overload my constructors in PHP, so what I'd really like to know is why. Is there even a reason for it? Does it create inherently bad code? Is it widely accepted language ...