oop

PHP: Object oriented vs. MVC (CodeIgniter)

We are starting a new app and are debating the benefits of MVC (using CodeIgniter for PHP) vs. using object oriented PHP. I myself only really started using object oriented PHP, and do like it, but should I use that over codeigniter? I see benefits of both. ...

Should protected attributes always be banned ?

I seldom use inheritance, but when I do, I never use protected attributes because I think it breaks the encapsulation of the inherited classes. Do you use protected attributes ? what do you use them for ? ...

DoSomethingToThing(Thing n) vs Thing.DoSomething()

What factors determine which approach is more appropriate? ...

Good book to learn to program well in Java (engineering or architecture-wise, not syntax)

I'm looking for a book to learn to "engineer" programs better. I program in Java already. Looking at the source code of open-source projects usually is too complicated as I have never made a program with more than 20 small files in it. I'm not an advanced programmer, I learned with a book and do this mostly for personal projects. My las...

Is there a benefit to defining a class inside another class in Python?

So what i'm talking about here are nested classes. So essentially I have two classes that I'm modeling. I have a DownloadManager class and a DownloadThread class. The obvious OOP concept here is composition. However, composition doesn't necessarily mean nesting, right? So I have code that looks something like this: class DownloadThread...

Get Methods: One vs Many

getEmployeeNameByBatchId(int batchID) getEmployeeNameBySSN(Object SSN) getEmployeeNameByEmailId(String emailID) getEmployeeNameBySalaryAccount(SalaryAccount salaryAccount) or getEmployeeName(int typeOfIdentifier, byte[] identifier) -> In this methods the typeOfIdentifier tells if identifier is batchID/SSN/emailID/salaryAccount Which o...

C++ Class design from database schema

I am writing a perl script to parse a mysql database schema and create C++ classes when necessary. My question is a pretty easy one, but us something I haven't really done before and don't know common practice. Any object of any of classes created will need to have "get" methods to popluate this information. So my questions are twofol...

Is there any way to detect the target class in PHP 5 static methods?

Below is an example class hierarchy and code. What I'm looking for is a way to determine if 'ChildClass1' or 'ChildClass2' had the static method whoAmI() called on it without re-implementing it in each child class. <?php abstract class ParentClass { public static function whoAmI () { // NOT correct, always gives 'ParentCl...

OO PHP explanation For a braindead n00b

Hi guys, I've been writing PHP for about six years now and have got to a point where I feel I should be doing more to write better code. I know that Object Oriented code is the way to go but I can't get my head around the concept. Can anyone explain in terms that any idiot can understand, OO and how it works in PHP or point me to an id...

Object Oriented Update Approach

I've been tasked with maintaining an application originally written in VB6. It has since been imported into VB .Net and to say the least the code is anything but Object Oriented. The code is riddled with classes which contain nothing more than Public Shared attributes(variables) and methods(functions), the result of which restricts the a...

How do you know when to use design patterns?

Anyone can read the GoF book to learn what design patterns are and how to use them, but what is the process for figuring out when a design pattern solves a problem? Does the knowledge of the pattern drive the design, or is there a way to figure out how a pattern can be used to change a design? In other words, are there patterns for Patt...

When should I use a struct instead of a class?

MSDN says that you should use structs when you need lightweight objects. Are there any other scenarios when a struct is preferable over a class? Edit: Some people have forgotten that: 1. structs can have methods! 2. structs have no inheritance capabilites. Another Edit: I understand the technical differences, I just don't have a good f...

Proper Logging in OOP context

Here is a problem I've struggled with ever since I first started learning object-oriented programming: how should one implement a logger in "proper" OOP code? By this, I mean an object that has a method that we want every other object in the code to be able to access; this method would output to console/file/whatever, which we would use...

What's wrong with singleton?

Do not waste your time with this question. Follow up to: http://stackoverflow.com/questions/137975/what-is-so-bad-about-singletons Please feel free to bitch on Singleton. Inappropriate usage of Singleton may cause lot of paint. What kind of problem do you experienced with singleton? What is common misuse of this pattern? After som...

When would you need to use late static binding?

After reading this description of late static binding (LSB) I see pretty clearly what is going on. Now, under which sorts of circumstances might that be most useful or needed? ...

Is There Any Advantage in Passing a UI wrapper to a view

Most of the MVC samples I have seen pass an instance of the view to the controller like this public class View { Controller controller = new Controller(this); } Is there any advantage to passing a class which provides access to just the the properties and events the controller is interested in, like this: public class UIWrappe...

What are the benefits of the Iterator interface in Java?

I just learned about how the Java Collections Framework implements data structures in linked lists. From what I understand, Iterators are a way of traversing through the items in a data structure such as a list. Why is this interface used? Why are the methods hasNext(), next() and remove() not directly coded to the data structure impleme...

Dependency Injection and Circular reference

I am just starting out with DI & unit testing and have hit a snag which I am sure is a no brainer for those more experienced devs : I have a class called MessageManager which receives data and saves it to a db. Within the same assembly (project in Visual Studio) I have created a repository interface with all the methods needed to access...

Is it just me or are interfaces overused?

Ok, I may resort to a tad ranting here, so let me apologize in advance, but I'm really curious if others find this pattern annoying too (and I wonder if it is a justifiable pattern)… So, after just looking at a particular question, I noticed that almost all of the responses suggested creating an interface for injecting a mock in some te...

Multiple Inheritance in PHP

I'm looking for a good, clean way to go around the fact that PHP5 still doesn't support multiple inheritance. Here's the class hierarchy: Message -- TextMessage -------- InvitationTextMessage -- EmailMessage -------- InvitationEmailMessage The two types of Invitation* classes have a lot in common; i'd love to have a commo...