oop

Are Interfaces just "Syntactic Sugar"?

I've been playing mostly with PHP and Python. I've been reading about Interfaces in OO programming and can't see an advantage in using it. Multiple objects can implement the same interface, but multiple inheritance doesn't provide this as well? Why do I need to create an Interface "with no implementation" - mainly a "contract" - if I ...

Is a class instantiated when a static method is called in a non-static class?

Exactly what happens when Foo.SomeCheck() is called in the Bar class? Is an instance of Foo created in order to call SomeCheck()? If so, is this instance stored on the heap, and is it ever collected through garbage collection? public class Foo() { public static bool SomeCheck() { return true; } } public class Bar() { ...

PHP OOP Cart Class display

Hi, I made an PHP OOP Cart Class like this print_r($_SESSION["cart"]); the result is: Array ( [1] => 1 [3] => 2 ) How can I print this session, like a "real" cart? example: echo "Your basket: "; echo "ItemID: ".$cartid." Itemnumber:".$cartnumber; The adding to basket part: if (isset($_POST['submit'])) { $cart= new Cart(...

Having trouble getting rid of redundant code via inheritance or generics

Sorry for the vague title, but I wasn't sure how to summarize this in one phrase. I have a situation with a lot of redundant C# code, and it really looks like some kind of crafty trick using some property of inheritance or generics would solve this. However, I'm not a terribly experienced programmer (particularly with C#) and just can't ...

Class passing it self

I have a class that creates the object of type Smo. The object then calls a static method from another class. The static method requires that I pass the object to it that is calling it. How do I designate the calling object as the parameter to pass. For example: class Smo { Smo() { } void sponge() { car.dancin...

In what situations is an OOP design approach suboptimal?

Possible Duplicate: Pitfalls of Object oriented programming I recently had an argument with a friend who believed that every application should be designed in an OOP manner. I know that there are definitely applications where OOP would not fit well over the design but could not think of any specific example. Can someone give m...

PyUnit with a variable number of tests

What I would like to do, is create a folder, where people can put in a file for testing, and have pyunit automatically expand in order to run the test as a separate test. Currently, what I'm doing is: class TestName(unittest.testcase): def setUp(self): for file in os.listdir(DIRECTORY): # Setup Tests def te...

Python: Can a class forbid clients setting new attributes?

I just spent too long on a bug like the following: >>> class Odp(): def __init__(self): self.foo = "bar" >>> o = Odp() >>> o.raw_foo = 3 # oops - meant o.foo I have a class with an attribute. I was trying to set it, and wondering why it had no effect. Then, I went back to the original class definition, and saw that the a...

Object as a data member in Objective C

From what I have experienced it seems as if objects cannot be shared data members in objective c. I know you can init a pointer and alloc the object in each method but I cannot seem to figure out how one can say define a NSMutableString as a data member and allow all of the methods to use and modify its data as in c++. Is this true or am...

abstract class in java

Can someone please show me and example of an abstract class in Java? Something with a real world application (rather than a text-book sample) would be preferable. Thanks! ...

How to set properties of an object dynamically, from a variable name?

I'm trying to populate a template with variables from a database. The data looks as follows: id field content 1 title New Website 1 heading Welcome! 1 intro This is a new website I have made, feel free to have a look around 2 title About 2 heading Read all about it! What I need to do with that data...

Use of "getTypeInstance()" of a Product in Magento

Can anybody please put some light on the need of the method "getTypeInstance()", which can be use by any product object? Also what are the pros & cons of using this method? ...

What is a class with only attributes called?

Is there a name or nickname for a class that only contain attributes (like a c struct)? Like DialogParameters in this example: public class MyDialog extends JDialog { public static class DialogParameters { public String dialogTitle; public String helpId; } public MyDialog(DialogParameters parameters) { ... } } ...

Python - passing object references ?

Hi I learning Python (coming from a dotnet background) and developing an app which interacts with a webservice. The web service is flat, in that it has numerous calls some of which are related to sessions e.g. logging on etc, whereas other calls are related to retrieving/setting business data. To accompany the webservice, there are ...

Scope of pure virtual functions during derived class destruction - In C++

Hi, During destruction of the derived class object, i first hit the derived class destructor and then the base class destructor (which is as expected). But i was curious to find out - at what point does the functions of the derived class go out of scope (are destroyed). Does it happen as soon as the control leaves the derived class des...

How to refactor an existing class to become polymorphic?

I have a class that is used as a member in many places in my project. Now, instead of this class I want to have a polymorphism, and the actual object will be created by some kind of factory. I have to choose between: Having to change all the places where I use the class - to call the factory and use a pointer instead of object directl...

list of VBA OOP Concepts

Hi All, I am building some material for OOP (object oriented programming) in VBA, so can anybody list me the OOP concepts which are available in VBA? for example from my reading I discovered that: inheritance is not available in VBA !!! encapsulation concept is there as you can use access modifier "private" and build a public propert...

In OOP, should dependencies hold a reference to their parent?

I have an Order object to represent a Prospective Order/Receipt. This is an entity. It has an identity. I have a Writer object to read the Order object's properties and display it nicely. It is a bit of a chore to have individual getters for all the pieces of the Client's Billing Details. So, I am thinking of letting the Writer object...

Resource server desgin for Enterprise apps

Hi, I am working on design for a resource server. I want to gather some industry best practices on it. Scenario: A data driven portal application hosted on a web farm. Whenever a request comes, controls are rendered and response is sent. For each image on the page, browser requests for the image separately using a webservice. Since ...

A good Object-Oriented analogy

I'm looking for a good way to describe OO to beginners, though an analogy. Currently I'm likening a Class to a shopping list, and a shopping trolley full of items to an object. But I feel it's a bit confusing. Preferably the analogy would be reflected well in the code example (Ruby), currently I have this, and it feels klunky. # First...