oop

Object oriented JavaScript help

Hi, I have the following code: var HD = function() { }; HD.Car = (function() { var _date = "09/07/2010"; return { Make: undefined, Model: undefined, showMakeAndModel: function() { document.write(this.Make + " " + this.Model + " (data co...

What is the best way to DRY up these classes, duplication in everything but constructor

So I did some refactoring and two of my classes now look exactly the same except for their constructors. The classes wrap an API object that isn't very pretty, and add some functionality that belong at the edge of the API. class A extends API { public A { this.APIOption = Option1; this.AnotherAPIOption = Option2; // a few...

Overloading best practices

Say I have a method that returns a business object: public static MyObject GetObject() { return Blah.Blah(); } Now I need another method that does the same thing, but returns MyObject in an XML format: public static string GetObject(bool returnXml) { return Blah.Blah.Xml(); } I started with this approach, but soon realized tha...

Checkbox setState:0 on app launch

Hi, I'm having a problem with a checkbox. I want to set it to 0 (unchecked) on app launch, but the checkbox is controlled by another class "myClass" for example. Here's what I did: I opened Interface Builder and put a checkbox (NSButton) in my window, dragged NSObject in my MainMenu.xib window, renamed it to say "myClass". Added an o...

Accessing data in kohana validation

Hi there, i'll try and be as clear as possible. I'm working on some form validation using the wonderful kohana framework. However i have come at a crossroads and not sure whether the way i have taken is a wise choice. Basically, i have a date selector using several select boxes (i toyed with the idea of using javascript date pickers b...

Reading/Writing intermediate values from/to disk

Hi, I am currently working on this application(C#,WPF,LINQ2XML,.NET 4.0) that displays details for 'Animals'. An example of this would be the application displaying the types of Animals such as 'Birds','Mammals','Reptiles'. For each type of Animal, I will have sub-entries such as for 'Birds' I will have sub-entries like 'Sparrow','Hawk'...

Casting to a custom user class

While I was trying to build a Number subclass in AS3 I noticed I cannot extend the Number/int/etc. classes --- they are final. The next best thing was casting. Still, I also don't think this is possible but since I've been asking myself this for a while I said I'd ask here to find out. Can you create custom casting for a class you crea...

when to use new in C++?

What's a good policy for when to use "new" to make an instance of a class? I've been hobby programming C++ for a while but I'm still not for sure when is the best time to do this: MyClass thing(param1, param2); over this: MyClass* thing; thing = new MyClass(param1, param2); Any advice? ...

Very long class names

I try to name a class (also members, properties and so forth) as exact as I can. But sometimes I’m not sure if this is so clever if the class name becomes huge (50 chars and more). The handling is so what uncomfortable and the code becomes difficult to read. The question occured for me seldom and therefore I don’t have much experience ...

PHP overloading a function from a parent class

Hi all, I have a thing which I thought should work, but it doesn't. I have several Controller_## classes, they all extend from Controller_Core. Each Controller_##-class has a public function Save(). Now I figured that I want to perform some other general checking (addslashes for each $_POST-var) and thought if I add a public function S...

Assigning values to Object

Hello All, Does the given code samples perform same operation? Do i really need a EXTRA object instantiation code? Will there be any issue with the first code segment? Sample 1 Dog adog= new Dog(); adog.ID = dogID; adog.CategoryId= dogCategoryId; adog= DogRepository.FindDogByCategoryId(adog); Assign the values back to the same obje...

PHP getter/setter to array

Following "problem" PHP Class with a lot of propertys. A lot of Getters / Setter. Is there any nice solution to convert all propertys to an array? protected $name; protected $date; public function getName(); public function getDate(); public function asArray(); // call all getters? ...

Do I've to set variable to null always in AS3 OOP?

Hello, I've a question about variables in AS3 OOP. Do I have to set them to null or I it's not needed when I define them in beginning of the class? I just noticed someone doing so so I wasn't sure is it right or no. private var _mcComponentHolder:MovieClip = null; private var _mcComponentHolder:MovieClip; Thanks in advance! ...

Java Program Organization: How can I get rid of this massive case statement?

I am creating a program that will fill in a given grammar. Right now I am modeling the "kinds of words" like this: public class WordDescriptor { public static final String noun = "N"; public static final String plural = "p"; public static final String nounPhrase = "h"; public static final String usuParticipleVerb = "V"...

JavaScript pattern for multiple constructors

I need different constructors for my instances. What is a common pattern for that? ...

Javascript: should I be hiding my implementations?

As a C# programmer, I have a bit of a habit of making things private that can and should be private, and I always get a weird feeling when a JS type exposes all its private parts to me (and that feeling is not 'aroused'). Say I have a type that has a draw method, which internally calls drawBackground and drawForeground, which make no sen...

C++ difference between reference, objects and pointers

This is a question from an exam in an advanced course in OOP, taught in C++ (in TAU university, this semester): Q: What is the difference between a C++ pointer and a reference? A. A reference is the entire object while a pointer is only the address of it. B. The same meaning, and difference is only in syntax and usage. C. The sy...

factory class in PHP, no __construct? What method names do I use?

I have a factory class I'm making in PHP. Each instance represents a row from a database table. Since I'll be dealing with dozens of database rows, it would be silly to have each instance do a select on instantiation. So I have a method to just dump values in to the object, for use in conjunction with a database query that returns a lo...

need help in understanding the code

class Problem: """ This class outlines the structure of a search problem, but doesn't implement any of the methods (in object-oriented terminology: an abstract class). """ def getStartState(self): """Returns the start state for the search problem""" sahan.raiseNotDefined() Now I want to know th...

What design is better: universal builder or several concrete methods?

I need to create an email-notification service (as a part of a bigger project). It will be used to send several types of notification messages which are based on html-templates. I can design it in two ways: The first way is based on the builder pattern. It's universal (as I think) and can handle all necessary cases. But it's not ve...