oop

Cloning an abstract object in java

I am trying to grab an object from an array list and copy it to another array list. as per a request public abstract class codeType{ stuff } public class drawOval extends codeType{ } main{ arrayList<codeType> a arrayList<codeType> b a.add(new drawOval(stuff)) a.add(new drawOval(other Stuff)) b.add(a.get(0)...

Shouldn't __metaclass__ force the use of a metaclass in Python?

I've been trying to learn about metaclasses in Python. I get the main idea, but I can't seem to activate the mechanism. As I understand it, you can specify M to be as the metaclass when constructing a class K by setting __metaclass__ to M at the global or class level. To test this out, I wrote the following program: p = print class M(t...

Sharing objects between PHP classes

What is the best way to share objects between other classes? For example; a "database" object with functions that are required by the "article" and "user" objects. I don't want to use globals (that includes singletons) or create a new instance of the object in each class, such as function __construct() { $this->database = new dat...

class for different uses

I have a class that is being used by two different processes with each process using different properties of the class. Everytime a process requires a new property I simply add it to the class. Is this a bad idea? Should I just create two separate classes and update them when required? N.B. At times the same property is being used by bo...

What is the difference between a namespace, a class, an object and an instance?

I'm reading Heads First C# (it's very interesting and user-friendly), but I wondered if anyone had a useful metaphor for describing how Name spaces, Classes, methods, properties, etc. all 'fit together'? Is Class a Parent and a Method a child, etc. Or is it more complicated? Could a Name Space be a house, and a Class be a room (Bathroo...

jQuery class is statically sharing an object across class instances

A while ago I needed to create an object orientated class using jQuery. I turned to use John Resig's fine Class solution. Hit an issue with it. When I define a global options object, it seems to me that the latter is shared amongst classes. I have confirmed that by printing various console.log's after modifying the object in one class o...

Is Inversion of Control specific to OO languages?

Another way to ask this question is: what is Inversion of Control according to you? I ask this question because the Wikipedia article on IoC has been hijacked by a non-OO explanation. This is taken from the discussion page and is from 2007: I took the liberty to completely rewrite the page, as the previous content was completely tak...

Representing parameters/configurations/settings

Alright, so let's say I'm writing an application using an object-oriented language, and I have a set of key-value pairs that represent program parameters/configuration/options/settings/etc. These may be initial values of certain variables, or just values that aren't bound to change except between sessions. How should I represent these va...

Why to use class based OOP style inheritance in javascript?

If I'm not completely wrong every framework/library/approach in javascript tends today to mimick class based OOP style inheritance. Reasons for this seem to be people thinking class based OOP inheritance is far easier to understand and that most programmers know OOP. In my experience I don't find evidence for either of this opinions. I...

Accessing private instance variables of parent from child class?

Let's say we have a class foo which has a private instance variable bar. Now let us have another class, baz, which extends foo. Can non-static methods in baz access foo's variable bar if there is no accessor method defined in foo? I'm working in Java, by the way. ...

Should methods that throw RuntimeException indicate it in method signature?

For example, many methods in frameworks/JDK might throw java.lang.SecurityException but this is not indicated in the method signature (since that is a practice normally reserved for checked exceptions). I want to argue that declaring RuntimeExceptions in method sigs has many benefits (akin to static type checking for example). Am I d...

Is polymorphism another term for overloading?

Is polymorphism another term for overloading? ...

Dumb Question about examples in Test Driven Development By Example by Kent Beck

I suspect that I'm missing something stupid, so feel free to blast me, but: I'm reading through Test Driven Development: By Example and one of the examples is bugging me. In chapter 3 (Equality for all), the author creates an equals function in the Dollar class to compare two Dollar objects: public boolean equals(Object object) { D...

Does coding towards an interface rather then an implementation imply a performance hit?

In day to day programs I wouldn't even bother thinking about the possible performance hit for coding against interfaces rather than implementations. The advantages largely outweigh the cost. So please no generic advice on good OOP. Nevertheless in this post, the designer of the XNA (game) platform gives as his main argument to not hav...

What are the best scenarios for using object-oriented databases?

We are planning to use OO databases to store configuration objects. The options are: 1 - Create 300+ relational tables. 2 - Create a generic structure with few tables. We think this would make object relation mapping more complex to build and maintain. 3 - Use a OO database. We are testing this now. What do you think ? ...

Can you create class properties dynamically in PHP ?

Is there any way to create all class properties dynamically ? For example I would like to be able to generate all class attributes from the constructor and still be able to access them after the class is instantiated like this: $class->property. To be more specific, when I'm dealing with classes that have a large number of attributes I ...

Should web app domain objects containing collections have "add" and "remove" item methods?

Let's say I have a Person class that has a collection of Dog objects. The relationship is bidirectional. public class Person { private List<Dog> dogs; // getter and setter for dogs } public class Dog { private Person person; // getter and setter for person } Ok now if I was just working with these objects, I would have metho...

PHP Child class accessing Parent variable problem

I got this class: Class Username { protected $id; protected $username; protected $contact_information; private __construct($id) { $this->id = (int) $id; // Forces it to be a string $contact_information = new ContactInformation($this->id); } } Class ContactInformation extends Username { protected $mobile; ...

Hiding DAOs behind service, why?

Upon reviewing a bunch of MVC style web applications, I'm noticing that it's common to have a very large service interface sitting in front of the business layer. The implementation of this interface usually includes a bunch of DAOs. So you have something like: public class FoodServiceImpl implements FoodService { private FruitDAO ...

What are the benifits of learning F#?

I hear so much hype about F#. What makes functional programming so great? Is it really worth leaning? ...