oop

Nested records is sql server

select Table1.colID, Table1.colName, (select * from Table2 where Table2.colID = Table1.colID) as NestedRows from Table1 The above query gives you this error: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used..... Can anybody explain why this limitat...

How to construct two objects, with each other as a parameter/member

I have two classes that each need an instance of each other to function. Ordinarily if an object needs another object to run, I like to pass it in the constructor. But I can't do that in this case, because one object has to be instantiated before the other, and so therefore the second object does not exist to be passed to the first obj...

Python - Using __getattribute__ method

I want to override access to one variable in a class, but return all others normally. How do I accomplish this with __getattribute__? I tried the following (which should also illustrate what I'm trying to do) but I get a recursion error: class D(object): def __init__(self): self.test=20 self.test2=21 def __geta...

Using OOP for combining lots of functions (sort of namespace) in PHP?

Hi, I am working with PHP and I am wondering how bad practise it is to combine lots of funtions into a class. I am aware of it's not the purpose of classes, but the reason why I would do this is to provide a namespace. How big impact does it make to initiate let's say 10 classes at the execution of a PHP script isntead of let's say 2 or...

What is the object oriented programming computing overhead cost?

I have a large set of data (a data cube of 250,000 X 1,000 doubles, about a 4 gig file) and I want to manipulate it using a previous set of OOP classes I have written in Python. Currently the data set is already so large that to read into my machine memory I have to at least split it in half so computing overhead is a concern. My OOP c...

Get/Set in the c++ world, faux-pas?

I notice that get/set is not the c++ way as far as I can tell by looking at boost/stl, and even reading the writings of some of the top c++ experts. Does anyone use get/set in their c++ class design, and can someone suggest a rule of thumb on where if at all this paradigm belongs in the c++ world? It is obviously very popular in Java, ...

override ActiveRecord attribute methods

An example of what I'm talking about: class Person < ActiveRecord::Base def name=(name) super(name.capitalize) end def name super().downcase # not sure why you'd do this; this is just an example end end This seems to work, but I was just read the section on overriding attribute methods in the ActiveRecord::Base docs (...

Private/protected inheritance

In C++, I can't think of a case in which I would like to inherit private/protected from a base class: class Base; class Derived1 : private Base; class Derived2 : protected Base; Is it really useful? ...

PHP - What should I call the information stored in my Page class?

Hi Stackers I have a class named Page with a private property currently called _pageData which stores all the information (such as title, content, keywords etc). However, this to me doesn't look so good when I refer to it $this->_pageData. I want to think of a better name, and I'd imagine there would probably be a standard or 'best pr...

Inheritance design using Interface + abstract class. Good practice?

I'm not really sure how to title this question but basically I have an interface like this: public interface IFoo { string ToCMD(); } a couple of absract classes which implement IFoo like: public abstract class Foo : IFoo { public abstract string ToCMD(); } public abstract class Bar : IFoo { public abstract string ToCMD()...

PHP - Where is the best place to initiate a database class?

I recently took my Db initiating code out of the __construct of my Page class and placed it just after I initiate the Page class. I removed it from within the Page class because I want to be able to access it from anywhere (other classes for example). It also takes server, username, password and database arguments to it when initiated, a...

Inversion of Control in Compilers

Has anyone out there actually used inversion of control containers within compiler implementations yet? I know that by design, compilers need to be very fast, but I've always been curious about how IoC/DI could affect the construction of a programming language--hot-swappable syntaxes, anyone? ...

OOP and MVC programming style

I'm writing some data analysis software and decided to use such approach: epn: model/data.py <- Model definition model/reader.py <- How to read data into model view/gui.py <- main gui frame (wx) view/dialogs.py <- different dialogs (wx) epn.py <- controller For communication between gui and data I used wx.lib.pubsub. So when button 'Mo...

Method overloading behaviour

I have the following code sample : public class Base { public virtual void MyMethod(int param) { Console.WriteLine("Base:MyMethod - Int {0}", param); } } public class Derived1 : Base { public override void MyMethod(int param) { Console.WriteLine("Derived1:MyMethod - Int {0}", param); } public...

Diamond inheritance (C++)

I know that having diamond inheritance is considered bad practice. However, I have 2 cases in which I feel that diamond inheritance could fit very nicely. I want to ask, would you recommend me to use diamond inheritance in these cases, or is there another design that could be better. Case 1: I want to create classes that represent diffe...

How can I best apply OOP principles to games and other input-driven GUI apps?

Whenever I try to write graphical programs (whether a game or really any GUI app) I always wind up with one or two god classes with way too many methods (and long methods, too), and each class having far too many responsibilities. I have graphics being done at the same time as calculations and logic, and I feel like this is a really bad ...

Should we always favor polymorphism over enums?

After watching: The Clean Code Talks -- Inheritance, Polymorphism, & Testing I checked my code and noticed a few switch statements can be refactored into polymorphism, but I also noticed I only used switch statements with enums. Does this mean enums are "evil" in OO-design and should be eliminated with polymorphism? ...

Documentation about Roles

Hello, some time ago I found an article (Roles: Composable Units of Object Behavior) describing the pros of using Roles versus Interfaces or other ways of dealing with behavior requirements. Does any of you knows where I can find more literature about that, or knows more about Roles? I know that that's almost a research topic, but maybe...

In what circumstances should I use a Singleton class?

Closed as exact duplicate of this question. But reopened, as the other Singleton questions are for general use and not use for DB access I was thinking of making an internal data access class a Singleton but couldn't convince myself on the choice mainly because the class has no state except for local variables in its methods. What is ...

Teaching systems analysis and design - how much programming experience is needed?

I teach a one semester University course in systems analysis and design. Topics include design patterns, UML, OOP, software development lifecycles, and the history, benefits and drawbacks of various methodologies (such as Agile/SCRUM/BDUF/Waterfall.) Students who enter the course should have some exposure to programming, but in reality ...