oop

Why can't I declare C# methods virtual and static?

I have a helper class that is just a bunch of static methods and would like to subclass the helper class. Some behavior is unique depending on the subclass so I would like to call a virtual method from the base class, but since all the methods are static I can't create a plain virtual method (need object reference in order to access vir...

Book recommendation for learning good PHP OOP?

Hi, I've been coding PHP on and off for a few years, mostly some basic apps and sites. Not very much OOP at all. I've done some basic OOP but I don't really know if I'm doing it correctly or if I'm following best practices etc. I know PHP pretty well but up until now my code has mostly been functional with some minor OOP. Now I want to...

What is meant by the term "true" object orientation

I have been hearing a lot about Ruby and possibly even Javascript being "true" object oriented languages as opposed to C++ and C# which are class oriented (or template based) languages. What is meant by true OO and what are the advantages of this over the class/template approach? ...

What the best way to access the databse inside a class in PHP?

I have a session class that needs to store session information in a MySQL database. Obviously I will need to query the database in the methods of this class. In general I may need to connect more than one database simultaneously and may or may not be connected to that database already. Given that, what's the best way to access datab...

Correct approach to Properties.

I am working in Java on a fairly large project. My question is about how to best structure the set of Properties for my application. Approach 1: Have some static Properties object that's accessible by every class. (Disadvantages: then, some classes lose their generality should they be taken out of the context of the application; they...

Should a user interface be implemented using the Singleton design pattern?

I can't think of many reasons (or any at all) in which multiple independent user interfaces should be instantiated in a desktop application. Is it good practice to implement the UI as a singleton? Are there are advantages or disadvantages to this approach? ...

Misused design patterns

Are there, in the canonical Gang of Four list, any design patterns that you often find misused, misunderstood or overused (other than the highly debated Singleton)? In other words, is there a design pattern you would advise to think twice before using? (And why?) ...

a struct doesn't belong in an object oriented program ...

Or does it? Should an object-oriented design use a language construct that exposes member data by default, if there is an equally useful construct that properly hides data members? EDIT: One of the responders mentioned that if there's no invariant one can use a struct. That's an interesting observation: a struct is a data structure, i....

Any sensible examples of creating inheritance without creating subtyping relations?

I've been teaching OOP and was trying to convey to my students the important difference between inheritance and the creation of a subtype relation between two types. For example, in C++, I could use private inheritance to ensure that nobody outside sees the subtyping relation. However, while I can think of a lot of situations where I wo...

What is the best way to pass data between a MainFrame (or Main Dialog) and a Modal Dialog?

I need a modal dialog to gather some user input. I then need the same data to be consumed by the application MainFrame. Usually my Modal Dialog would have a pointer to some DataType able to store what I need, and I'd be passing this object by reference from the MainFrame in order to be able to recover data once the modal dialog is clos...

When do you stop encapsulating?

I have some event handler on a boundary class that manages a persistence mechanism for a given generic transaction: void MyBoundaryClass::MyEventHandler(...) { //retrieve stuff from the UI //... //declare and initialize trasaction to persist SimpleTransaction myTransaction(.../*pass down stuff*/); //do some other checks //.....

Is a Java interface an abstract class?

I'm working through some homework and a question on a previous exam paper asks to name all of the abstract classes in a given UML diagram. Fairly straightforward, I suppose. There is one abstract class and three interfaces. Do these interfaces qualify as abstract classes, in general? ...

What is the difference between a Functor and the Command pattern?

I am very familiar with the Command pattern, but I don't yet understand the difference in theory between a Functor and a command. In particular, I am thinking of Java implementations. Both are basically programming "verbs" represented as objects. However, in the case of functors, as I have seen from some examples anonymous inner class im...

Why Doesn't C# Allow Static Methods to Implement an Interface?

Why was C# designed this way? As I understand it, an interface only describes behaviour, and serves the purpose of describing a contractual obligation for classes implementing the interface that certain behaviour is implemented. If classes wish to implement that behavour in a shared method, why shouldn't they? Here is an example of wh...

Is it safe to make an old-style class into a new-style class using Multiple Inheritance?

In a program that I'm writing, I wanted to make a ConfigParser that's read only so that it can safely be used globally. I didn't realize this, but apparently the SafeConfigParser is an old-style class, thus I had to subclass it like this: class ConstParser(SafeConfigParser, object): """This is a implementation of the SafeConfigPar...

n-tier object mapping help

Hi all. Wondering if my approach is ok or could be improved: Public Class Company private _id as Integer private _name as String private _location as String Public Function LoadMultipleByLocation(Byval searchStr as String) as List(Of Company) 'sql etc here to build the list End Function End Classs Thoughts on having...

Object modeling references

What are some of the good books on object modeling... I am basically looking for a prerequisite book for Analysis Patterns by Martin Fowler.. ...

Class Variables in Javascript

I'm having a bit of trouble trying to get class variables to work in javascript. I thought that I understood the prototype inheritance model, but obviously not. I assumed that since prototypes will be shared between objects then so will their variables. This is why this bit of code confuses me. What is the correct way to implement...

"Is a" vs "Has a" : which one is better?

Portfolio A -> Fund 1 Portfolio A -> Fund 2 Portfolio A -> Fund 3 I couldn't frame my sentence without not using is/has. But between 1 & 2, 1) has a: class PortfolioA { List<Fund> obj; } 2) is a: class PortfolioA : List<Fund>{...} which one do you think is better from the point of extensibility, usableness, and what have you...

What is the best way of implementing a stack of more than one type of object in C#?

I'm writing an implementation of a virtual machine in C#, and I need to implement the VM's stack, which can contain two types of entry - return entries or backtrack entries. What is the best way of implementing this? I'm currently using a base type, as follows: class StackEntry { } class Return : StackEntry { uint pc; } class Backtrack...