oop

Why is sqrt() not a method on Numeric?

In Ruby everything is an object. That's why I don't understand why we have the Math module. It seems to me that most (all?) of the functions in the Math module should have been methods on the numeric types like Integer, Float and so on. E.g. instead of Math.sqrt(5) it would make more sense to have 5.sqrt The same goes for sin, co...

Why is an interface or an abstract class useful? (or for what?)

So my question is, why to use interfaces or abstract classes? Why are they useful, and for what? Where can i use them intelligently? ...

Am I trying to Implement Multiple Inheritance. How can I do this.

I have created a class say A which has some functions defined as protected. Now Class B inherits A and class C inherits B. Class A has private default constructor and protected parameterized constructor. I want Class B to be able to access all the protected functions defined in Class A but class C can have access on some of the functio...

GUI system architecture?

I'm designing GUI (graphical user interface) system for a game engine (C++). Idea is to create a heirarchy of GUI controllers like Focusable, Hoverable, Dragable etc. Every GUI component can attach multiple controllers, they modify component's behaviour. I think it gives flexible system and protects from code duplication. Different ins...

Building big, immutable objects without using constructors having long parameter lists

Hi StackOverflow! I have some big (more than 3 fields) Objects which can and should be immutable. Every time I run into that case i tend to create constructor abominations with long parameter lists. It doesn't feel right, is hard to use and readability suffers. It is even worse if the fields are some sort of collection type like lists....

characteristics of the abstract class

Hello All, I like to know what makes a class to be called as absract class. I believe, abract key word definetly make a class class, but if one takes out the keyword, then we can create the instance of the class. In otherwords, what are the characteristics of the abstract class. Thanks in advance. -Harsha ...

[Java/OO] Question about the design of dynamic subclass hierarchy handling.

I always tend to run into the following design problem that I'm never quite sure how to best resolve. It usually starts with a hierarchy of Animals at my Circus: Animal Cat BigCat Dog Elephant ... Now, each Animal needs to be trained, so that there is a separate method for each: public interface Trainer { v...

Getting my head around object oriented programming

I am entry level .Net developer and using it to develop web sites. I started with classic asp and last year jumped on the ship with a short C# book. As I developed I learned more and started to see that coming from classic asp I always used C# like scripting language. For example in my last project I needed to encode video on the webser...

Short intruduction to OOP basics

Hi. Can somebody point me to good intruductions into OOP main paradigms, like inheritance, polymorphism, encapsulation? I am looking for short article, about 2-3 pages, for very quick reading. Thank you very much. ...

Disadvantage of OOP?

Typically i dont want to know the specifics of the cons of OOPs, but it felt kind of weird when I had an argument at an interview I attended recently. The question that was posted to me was to tell me one disadvantage of OOP (Object Oriented Programming). At that time, I felt OOP to be the most matured level of programming after the proc...

Validating class and superclass on RoR

In ruby, you have an attribute called "type" which is the class of the object. Rails stores this at the database in a column called type. So, if I have several blog "types", I can do something like this def create @blog = Blog.new(params[:blog]) @blog[:type] = params[:blog][:type] # ... end If I add someone like this, and then l...

Can I get an example please?

$starcraft = array( "drone" => array( "cost" => "6_0-", "gas" => "192", "minerals" => "33", "attack" => "123", ) "zealot" => array( "cost" => "5_0-", "gas" => "112", "minerals" => "21...

How to avoid "incomplete implementation" warning in partial base class

I have created a protocol that my classes need to implement, and then factored out some common functionality into a base class, so I did this: @protocol MyProtocol - (void) foo; - (void) bar; @end @interface Base <MyProtocol> @end @interface Derived_1 : Base @end @interface Derived_2 : Base @end @implementation Base - (void) foo{ //...

Abstract base class to force each derived classes to be Singleton

How do I make an abstract class that shall force each derived classes to be Singleton ? I use C#. ...

Separating code logic from the actual data structures. Best practices?

I have an application that loads lots of data into memory (this is because it needs to perform some mathematical simulation on big data sets). This data comes from several database tables, that all refer to each other. The consistency rules on the data are rather complex, and looking up all the relevant data requires quite some hashes ...

Good code architecture for this problem?

I am developing a space shooter game with customizable ships. You can increase the strength of any number of properties of the ship via a pair of radar charts*. Internally, i represent each ship as a subclassed SpaceObject class, which holds a ShipInfo that describes various properties of that ship. I want to develop a relatively simple...

Help needed with JavaScript variable scope / OOP and call back functions

I think this issue goes beyond typical variable scope and closure stuff, or maybe I'm an idiot. Here goes anyway... I'm creating a bunch of objects on the fly in a jQuery plugin. The object look something like this function WedgePath(canvas){ this.targetCanvas = canvas; this.label; this.logLabel = function(){ console.log(th...

How to find out the subclass from the base class instance?

Is there a way to find out the name of derived class from a base class instance? e.g.: class A{ .... } class B extends A{ ... } class c extends A{ ... } now if a method returns an object of A, can I find out if it is of type B or C? ...

Creating An Utilities Class?

Hello SO, I'm very new to OOP and am trying my hardest to keep things strictly class based, while using good coding priciples. I'm a fair ways into my project now and I have a lot of general use methods I want to put into an utilities class. Is there a best way to create an utilities class? public class Utilities { int test; ...

C# Creating A Error Checking Class?

Hi StackOverflow, I'm very new to OOP, and in the program I'm working on, I have an Utilities class that contains some general methods. Should I include my error checking in the Utilities class or should I create a new class just for error checking? ...