Which constitutes better object oriented design?
Class User {
id {get;set}
}
Class Office {
id {get;set}
List<User> Managers(){ }//search for users, return list of them
}
or this one
Class User {
id {get;set}
List<User> Managers(){ }//search for users, return list of them
}
Class Office {
id {get;set}
}
...
I'm fairly new to C++, and I'm not sure about this one. Have a look at the following example which sums up my current problem.
class Foo
{
//stuff
};
class Bar
{
Foo foo;
};
So Bar constains a full Foo object, not just a reference or pointer. Is this object initialized by its default constructor ? Do I need to explicitly call...
I've seen a lot of this...
function myObject(data) {
var myData = data;
}
myObject.prototype.doSomething = function () {
alert("I did something!");
}
but the intellisense on Visual Studio gives me a .constructor for functions, which would lead me to believe this would be correct...
function myObject() {
var myData;...
I'd like to, for all helpers, across my entire Rails application, replace this syntax:
time_ago_in_words(@from_time)
with this:
@from_time.time_ago_in_words
Ideally this change would also make the helpers available anywhere in my application (the same way, say, 5.times is).
Does anyone know of a plugin that does this? Would it be ...
For a project I'm working on in Flex I decided to create several separate files for each 'theme' that can be used. Since each theme can and will require specific code, images, styles and virtually anything else, the classical css-only option was not really possible.
I have one problem with this method, and that's that each 'child' mxml ...
Consider the following code:
class Program
{
static void Main(string[] args)
{
Department deathStar = new Department { Name = "Death Star" };
Console.WriteLine("The manager of {0} is {1}.", deathStar.Name, deathStar.Manager.FullName);
deathStar.Manager.FirstName = "Lord";
Console.WriteLine("The...
Let's say I have an abstract class Drink, and a factory method which chooses the type of Drink (Wine, Beer, etc.) to create at runtime.
Each Drink needs some arguments to properly initialize itself. Some of these are common to all Drinks; for example, they might all require a DrinkConfig argument.
But each Drink may have its own unique...
How can I access a static variable in a separate class in PHP? Is the scope resolution operator the wrong tool for the job? Example:
class DB {
static $conn = 'Connection';
}
class User {
function __construct() {
DB::conn; //throws "Undefined class constant 'conn' error.
}
}
...
Hi,
can anyone explain what is Overloading, Overriding and Hiding in .Net?
Thanks
...
Suppose I have virtual function foo() in class B, and I need slightly different behavior in one of B's derived classes, class D. Is it OK to create an overriding function D::foo(), and call B::foo() from there, after the special case treatment? Like this:
void D::foo()
{
if (/*something*/)
// do something
else
B::foo();
}
...
So, a long long time ago I used to program procedurally initially with Basic on my first BBC Model B and then a small amount of Pascal at university as well as assembly along the way.
Then along came OO which seemed much more sensible all round and that was all I used with C++, Perl, Java, Ruby.....
Coming back to programming non web s...
In C# when I want to call a static method of a class from another static method of that class, is there a generic prefix that I can use such as PHP's self:: instead of the class name?
So in the below example, instead of saying Customer.DatabaseConnectionExists(), how can I say something like Self.DatabaseConnectionExists() so e.g. later...
Hello all.
Starting with Silverlight development. Yet to read a good Silverlight book: suggestions welcome.
I have a main GUI screen where 7 user controls (menu items) 'swoop' into sight, all along their own path. I have the user controls nicely seperated and behaving well. Having multiple storyboards (1 each for each menuitem) with mu...
In PHP+MySQL+PDO, would it be much slower to do
Get an item's ID by name
Get item data by ID
than to just
Get item data by name
The latter is only one query, so obviously faster. The former makes for cleaner code though (because the item's ID is often also just known beforehand), so it would be better if the performance differenc...
what is the difference between mix-in and inheritance
...
I am wondering what kind of methods are "helper methods". Where do we have to draw te border to say that an specific method is a "helper method"? Actually, I consider any method to be a "helper method" if it's not an initialization method, a method implemented for conforming to an protocol or delegation response methods. Any other method...
I ran across some code recently at work (recreated to be similar to what I am dealing with) similar to the code below
Is there a way I can rework the code below to use one data structure (with performance in mind)?
Here is some code to illustrate what I mean:
public class ObjectMapper {
private Map<UUID,Integer> uuidMap;
pri...
Consider this sample class,
class TargetClass {
private static String SENSITIVE_DATA = "sw0rdfish";
private static String getSensitiveData() {
return SENSITIVE_DATA;
}
}
When I do this,
import java.lang.reflect.Method;
public class ClassPiercing {
public static void main(String... args) throws Exception {
...
I was wondering, what is the preferred way to construct a new object in C#?
Take a Person class:
public class Person
{
private string name;
private int age;
//Omitted..
}
Should I create it to use:
New Person("name", 24);
or
New Person() { Name = "name", Age = 24 };
Is it just a matter of taste or is there a good...
In Java, you can do the following :
public interface IEngine{}
public interface ICoolEngine extends IEngine{}
public interface Car
{
IEngine getEngine();
}
public interface ICoolCar extends ICar
{
@Override
ICoolEngine getEngine();
}
While this nicely solves a problem I've been grappling with, something about it "feels" wr...