oop

How would you access Object properties from within an object method?

What is the "purist" or "correct" way to access an object's properties from within an object method that is not a getter/setter method? I know that from outside of the object you should use a getter/setter, but from within would you just do: Java: String property = this.property; PHP: $property = $this->property; or would you do:...

C++: Should I use nested classes in this case?

I am working on a collection of classes used for video playback and recording. I have one main class which acts like the public interface, with methods like play(), stop(), pause(), record()...etc. Then I have workhorse classes which do the video decoding and video encoding. I just learned about the existence of nested classes in C++, ...

Class views in Django

Django view points to a function, which can be a problem if you want to change only a bit of functionality. Yes, I could have million keyword arguments and even more if statements in the function, but I was thinking more of an object oriented approach. For example, I have a page that displays a user. This page is very similar to page th...

Object Oriented vs Relational Databases

Objects oriented databases seem like a really cool idea to me, no need to worry about mapping your domain model to your database model, no messing around with sql or ORM tools. The way I understand it, relational DBs offer some advantages when there is massive amounts of data, and searching an indexing need to be done. To my mind 99% of...

Adding a Method to an Existing Object

I've read that it is possible to add a method to an existing object (e.g. not in the class definition) in python, I think this is called Monkey Patching (or in some cases Duck Punching). I understand that it's not always a good decision to do so. But, how might one do this? And if you don't know python, can your language of choice do t...

Using object property as default for method property

I'm trying to do this (which produces an unexpected T_VARIABLE error): public function createShipment($startZip, $endZip, $weight = $this->getDefaultWeight()){} I don't want to put a magic number in there for weight, since the object I am using has a "defaultWeight" parameter that all new shipments get if you don't specify a weight. I ...

How to Think in OO

Besides the general, "What is OO?" question, I want to understand how one transitions from a procedural-based programmer to someone who gets OO. I'm anticipating the winning answer would contain thoughts on SOLID, as well as some practices/drills for increasing our skills in design and development that fully leverages OO. Books/classes...

pass by reference or pass by value?

When learning a new programming language, one of the possible roadblocks you might encounter is the question whether the language is, by default, pass-by-value or pass-by-reference So here is my question to all of you, in your favorite language, how is it actually done? and what are the possible pitfalls? your favorite language can, of...

Speed Comparisons - Procedural vs. OO in interpreted languages

In interpreted programming languages, such as PHP and JavaScript, what are the repercussions of going with an Object Oriented approach over a Procedural approach? Specifically what I am looking for is a checklist of things to consider when creating a web application and choosing between Procedural and Object Oriented approaches, to opti...

Multi-Paradigm Languages

In a language such as (since I'm working in it now) PHP, which supports procedural and object-oriented paradigms, is there a good rule of thumb for determining which paradigm best suits a new project? If not, how can you make the decision?...

Accessing a CONST attribute of series of Classes

This is how I wanted to do it which would work in PHP 5.3.0+ <?php class MyClass { const CONSTANT = 'Const var'; } $classname = 'MyClass'; echo $classname::CONSTANT; // As of PHP 5.3.0 ?> But I'm restricted to using PHP 5.2.6. Can anyone think of a simple way to simulate this behaviour without inst...

When is OOP better suited for?

Since I started studying object-oriented programming, I frequently read articles/blogs saying functions are better, or not all problems should be modeled as objects. From your personal programming adventures, when do you think a problem is better solved by OOP? ...

Why all the Active Record hate?

As I learn more and more about OOP, and start to implement various design patterns, I keep coming back to cases where people are hating on Active Record. Often, people say that it doesn't scale well (citing Twitter as their prime example) -- but nobody actually explains why it doesn't scale well; and / or how to achieve the pros of AR w...

How do you create objects in Perl?

Perl has OOP features, but they are somewhat rarely used. How do you create and use Perl objects with methods and properties? ...

How do you create a static class in C++?

How do you create a static class in C++? I should be able to do something like: cout << "bit 5 is " << BitParser::getBitAt(buffer, 5) << endl; Assuming I created the BitParser class. What would the BitParser class definition look like? ...

Do you name controls on forms using the same convention as a private variable?

For some reason I never see this done. Is there a reason why not? For instance I like _blah for private variables, and at least in Windows Forms controls are by default private member variables, but I can't remember ever seeing them named that way. In the case that I am creating/storing control objects in local variables within a memb...

Inheritance and Polymorphism - Ease of use vs Purity

In a project our team is using object lists to perform mass operations on sets of data that should all be processed in a similar way. In particular, different objects would ideally act the same, which would be very easily achieved with polymorphism. The problem I have with it is that inheritance implies the is a relationship, rather th...

Access to global application settings

A database application that I'm currently working on, stores all sorts of settings in the database. Most of those settings are there to customize certain business rules, but there's also some other stuff in there. The app contains objects that specifically do a certain task, e.g., a certain complicated calculation. Those non-UI objects ...

Expression Evaluation and Tree Walking using polymorphism? (ala Steve Yegge)

This morning, I was reading Steve Yegge's: When Polymorphism Fails, when I came across a question that a co-worker of his used to ask potential employees when they came for their interview at Amazon. As an example of polymorphism in action, let's look at the classic "eval" interview question, which (as far as I know) was brough...

Is Single Responsibility Principle a rule of OOP?

An answer to a Stack Overflow question stated that a particular framework violated a plain and simple OOP rule: Single Responsibility Principle (SRP). Is the Single Responsibility Principle really a rule of OOP? My understanding of the definition of Object Orientated Programming is "a paradigm where objects and their behaviour are used...