oop

Is there a commonly used OO Pattern for holding "constant variables"?

I am working on a little pinball-game project for a hobby and am looking for a pattern to encapsulate constant variables. I have a model, within which there are values which will be constant over the life of that model e.g. maximum speed/maximum gravity etc. Throughout the GUI and other areas these values are required in order to correc...

What's the difference between a procedural program and an object oriented program?

I'm fairly new to programming but I've been reading some interesting discussions on StackOverflow about various programming approaches. I'm still not 100% clear on what the difference is between procedural programming and object oriented programming. It sounds like object oriented programming still uses procedures (methods) but everythin...

Is there ever a case for 'new' when using dependency injection?

Does dependency injection mean that you don't ever need the 'new' keyword? Or is it reasonable to directly create simple leaf classes such as collections? In the example below I inject the comparator, query and dao, but the SortedSet is directly instantiated: public Iterable<Employee> getRecentHires() { SortedSet<Employee> entries ...

How can I give a large number of class methods "almost" the same code

hello I have this PHP class class myclass{ function name($val){ echo "this is name method and the value is".$val; } function password($val){ echo "this is password method and the value is".$val; } } and here is how to use it: $myclass= new myclass(); $myclass->name("aaa")//...

Multiple Inheritance Criticisms

I was investigating the concept of Multiple Inheritance (it's been almost 10 years since I have coded C++ in anger, and was simply academically interested in the concept). I found this reference on Wikipedia. One criticism of MI they list is "Not being able to explicitly inherit multiple times from a single class". I'm confused about th...

Misuse of the CSS class attribute, or valid design pattern?

As you most likely already know, it's simple in JQuery to select all elements in the document that have a specific CSS class, and then, using chaining, assign common event handlers to the selected elements: $(".toolWindow").click(toolWindow_click); $(".toolWindow").keypress(toolWindow_keypress); As usual the class "toolWindow" is also...

What is the relationship between "late binding" and "inversion of control"?

In his definition of OOP, Alan Kay points out he supports "the extreme late-binding of all things". Does his interest in late-binding share the same motivation as people's interest in IoC? In particular, would it be correct to say that both are motivated by the concept "specify as little as possible, and leave implementation details to ...

Dynamic dispatch and binding

Are dynamic dispatch and dynamic binding the same thing? Thanks Maciej ...

Creating a class to use for populating drop-down lists, grids, etc., in C#

Please keep in mind that I'm new to C# and OOP so I apologize in advance if this seems like an easy question to some. I'm going back through my code and looking for ways to objectify repetitive code and create a class for it so that I can simply reuse the class. That being said, I'm not looking to learn NHibernate or any other ORM just...

Is using reflection considered unOOPish?

What are the risks of using reflection? Does it go against OOP in any way? I started using it lightly in a C# project and now I find it practical in many scenarios. Thank you. ...

Is a function an example of encapsulation?

By putting functionality into a function, does that alone constitute an example of encapsulation or do you need to use objects to have encapsulation? I'm trying to understand the concept of encapsulation. What I thought was if I go from something like this: n = n + 1 which is executed out in the wild as part of a big body of code and ...

How do I tear down observer relationship in multithreaded C++?

I have a Subject which offers Subscribe(Observer*) and Unsubscribe(Observer*) to clients. Subject runs in its own thread (from which it calls Notify() on subscribed Observers) and a mutex protects its internal list of Observers. I would like client code - which I don't control - to be able to safely delete an Observer after it is unsub...

Packages in PHP?

Is it possible to create packages of related class and have the same protected and private fields which are visible only to classes from the same package? Basically, the same type of packages as what Java has? Is it possible? ...

OOP Design: Where should reusable validation be?

I've got a wizard which needs to validate if a user is logged in and then at the end validate that all the details they have entered are correct. The issue is I'm not sure where to put the validation logic. At the moment I have a BuyMembership class which has validation on the Buy() method. However this won't be called at the beginning ...

Fully Object Oriented framework in PHP

I want to create a 100% object oriented framework in PHP with no procedural programming at all, and where everything is an object. Much like Java except it will be done in PHP. Any pointers at what features this thing should have, should it use any of the existing design patterns such as MVC? How creating objects for every table in the ...

Tracking an objects state

Hi, In PHP, what's the best way to track an objects state, to tell whether or not it has been modified? I have a repository object that creates new entities, they are then read/modified by other components and eventually given back to the repository. If the object has changed I want the repository to save the data back to the persistent ...

Best practice: initialize same component in multiple classes.

This is my first question so please be patient :) Background: I'm implementing an observer pattern and I have about 20 classes where I would eventually implement it. In order to use the subject and observer I need to: 1: initialize observer classes 2: create delegates 3: add delegates to the events This is probably very simple, but I d...

Itereting hierarchy of nodes - Visitor and Composite ?

Let's imagine I have a collection of nodes that I use for my Renderer class later on. Then I have a Visitor class that can visit node or whole collection. It's simple because my collection of nodes it's simply a wrapper to the std::list with few extra methods. The problem is I'd like to have a tree like structure for nodes(instead of si...

Getting the name of a child class in PHP

Lets say I'm building a base class which will be extended upon by the children class. So a base class is called Base and children can be Child1, Child2, etc. In the base class's constructor, how can i get the value of Child1/Child2? This is all using PHP ...

Whats the best way to add variations of the same character to a view in Cocoa

I am confused about how to go adding objects (images,etc) into an app. I will keep my example very basic so I can get a grasp on this. Let's say I want simple objects in an app. Say they are the smilies like the ones that are available in this forum software. If you wanted to add a bunch (like 4 not 400) to a view, is it better to just a...