oop

Should an object searcher method be in the a parent object, or the same as the object beign searched?

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} } ...

C++ - construction of an object inside a class

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...

Object oriented programming with Javascript - Constructors

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;...

How can I make rails helpers more object-oriented

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 ...

AS3/Flex: How to make mxml files loaded via ViewStack see their parent's variables, etc.?

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 ...

Is assigning a value to a property through a set accessor via its container's get accessor a bad thing?

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...

Passing arguments to a specific subclass, through a factory method

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 do I call static variable in a separate class in PHP?

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. } } ...

Overloading,Overriding and Hiding?

Hi, can anyone explain what is Overloading, Overriding and Hiding in .Net? Thanks ...

Calling overridden function from the overriding function

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(); } ...

Mixing procedural and Object oriented programming

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...

What is the C# equivalent to PHP's "self::"?

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...

Silverlight DRY when animating multiple UserControls on main Navigation page.

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...

Two queries vs one query, performance

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...

mix-in vs inheritance

what is the difference between mix-in and inheritance ...

What would you consider to be called a "helper method"?

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...

Two Way Mapping using single Data Structure

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...

Accessing private static methods from a public static context

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 { ...

What is the preferred way of constructing objects in C#? Constructor parameters or properties?

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...

Overriding return type in extended interface - Bad idea?

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...