oop

Why can application developers do datasebase stuff but database developers try to stay clear of application stuff ?

In my experience, this has been a contentious issue between "backend" (database developer) and "frontend" guys (application developer, client and server side). There have been many heated pub discussions on this subject. I just want to know is it just people have different mindsets, or lazy to learn more and feel comfortable in what ...

Calling Static Method from Class B(which extends Class A) of Class A

There was an interesting question in a practice test that I did not understand the answer to. What is the output of the following code: <?php class Foo { public $name = 'Andrew'; public function getName() { echo $this->name; } } class Bar extends Foo { public $name = 'John'; public function getName() { F...

If-less code: is it just an intellectual challenge or is it concretely useful?

A friend of mine is talking about these design techniques regarding state transitions of an object (he's a Java guru, btw), performed without having a boolean myState member, but rather declaring the myState member as an object that implements the same interface of the "owner" one. Ok, I've been too much cryptic, so you can find the dis...

Is user logged in variable with PHP

Hi I've built a class called Login with a construct that either logs them in or it doesn't... I also have a static function called isAuthenticated which is meant to check if the user is logged in or not... I've been messing around with static functions etc but can't seem to get what I want. Ideally, it'd be where I can easily go <?php...

Code Refactor Class Pattern

I am currently trying to refactor my codebase for an app I am making, I have an existing setup but it is not even close to being flexible and everything is dependent on everything else (aggregated to each class for example). So, after reading PHP Design Patterns and countless articles on patterns and how they relate to scalable applicat...

How can Polymorphism replace an if-else statement inside of a loop?

How can polymorphism replace an if-else statement or Switch inside of a loop? In particular can it always replace an if-else? Most of the if-thens I use inside of loops are arithmetic comparisons. This question is spawned from this question. int x; int y; int z; while (x > y) { if (x < z) { x = z; } } How woul...

How can I tell the compiler not to create a temporary object?

I'm changing an old routine that used to take an integer parameter so that it now takes a const reference to an object. I was hoping that the compiler would tell me where the function is called from (because the parameter type is wrong), but the object has a constructor that takes an integer, so rather than failing, the compiler creates ...

C# TreeView design - best way to display a tree structure?

I'm trying to use a TreeView to display a tree structure of objects. I have a tree of four types of object, Company (the root node), City, Store and Employee. The interface is designed to add/remove Cities/Stores/Employees, so the TreeView has to update to reflect any changes. I am wondering on the correct way to get the TreeView to di...

looking for automated modeling tool for ASP.Net class diagramming

I'm walking into a project with 500+ classes, and am wondering if anyone has had good experiences with automated modeling tools that can import from ASP.Net /C#? It would be a bonus if I could get an automated model based on all the objects called to completely load a single ASP.Net page, with relationships indicating which objects are ...

Should objects delete themselves in C++?

I've spent the last 4 years in C# so I'm interested in current best practices and common design patterns in C++. Consider the following partial example: class World { public: void Add(Object *object); void Remove(Object *object); void Update(); } class Fire : Object { public: virtual void Update() { if(age ...

How can I simulate OO-style polymorphism in C ?

Is there a way to write OO-like code in the C programming language? See also: http://stackoverflow.com/questions/351733/can-you-write-object-oriented-code-in-c http://stackoverflow.com/questions/415452/object-orientation-in-c Found by searching on "[c] oo". ...

Best Resources to learn OO Design and Analysis

Hello, I am looking for the best resources, videos, books, magazines(I like videos) to learn and master Object Oriented design and analysis. I would really like to know more about trusted and reputable methodologies for structuring your programs, designing classes, and dealing with databases in your programs. So, my question is what are...

What things are best not done in a constructor?

I started off by drafting a question: "What is the best way to perform unit testing on a constructor (e.g., __construct() in PHP5)", but when reading through the related questions, I saw several comments that seemed to suggest that setting member variables or performing any complicated operations in the constructor are no-nos. The const...

Does Python have class prototypes (or forward declarations)?

I have a series of Python classes in a file. Some classes reference others. My code is something like this: class A(): pass class B(): c = C() class C(): pass Trying to run that, I get NameError: name 'C' is not defined. Fair enough, but is there any way to make it work, or do I have to manually re-order my classes to a...

Is having a ubiquitous base object an anti pattern?

I remember seeing a debate about this somewhere, and am currently considering removing a base object that every business object, in a system I'm working on, inherits from. It contains a few properties, some database logic, and some constructor logic. Is this an anti pattern, or is the jury still out? Would it be better to have a base co...

Can I instatiate a subclass object from the superclass

I have the following example code: class A(object): def __init__(self, id): self.myid = id def foo(self, x): print 'foo', self.myid*x class B(A): def __init__(self, id): self.myid = id self.mybid = id*2 def bar(self, x): print 'bar', self.myid, self.mybid, x When used, the follo...

Does procedural programming have any advantages over OOP?

[Edit:] Earlier I asked this as a perhaps poorly-framed question about when to use OOP versus when to use procedural programming - some responses implied I was asking for help understanding OOP. On the contrary, I have used OOP a lot but want to know when to use a procedural approach. Judging by the responses, I take it that there is a f...

Is there a cartoon guide to OOP?

I'm looking for some visuals for a presentation to illustrate the principles of oop in a simple-to-grasp way. I want to avoid saying stuff like "an object is a software bundle of related state and behavior". Has anyone seen a non-jargon-y illustrated guide to OOP? ...

Objective-C pointers?

Hi, I am new to coding and trying to get up to speed with Objective-C. Came across some code I did not understand. I was hoping someone could clarify it for me. In the case below, I am not sure how *foo2 is working and why it is not being released? ClassOne *pointer = [[ClassOne alloc]init]; ClassTwo *foo = [[ClassTwo alloc]init], *fo...

Parameter vs. Member variables

I've recently been working with someone else's code and I realized that this individual has a very different philosophy regarding private variables and method parameters than I do. I generally feel that private variables should only be used in a case when: The variable needs to be stored for recall later. The data stored in the variab...