oop

In PHP 5.x, how can I detect if a class is abstract or not at run time?

I'm looping through an array of class names in PHP, fetched via get_declared_classes(). How can I check each class name to detect whether or not that particular class is an abstract class or not? ...

What is the purpose of interfaces?

I want to understand the purpose of interfaces. I know how to declare an interface and how to implement the interface, but what is the need of it? I need to understand the reason for using interfaces. In every programming course, the teacher has said, "It is a contract. It has just definitions of methods and properties," and given an exa...

Static factory on business object a violation of Single Responsibility Principle?

Am I violating the Single Responsibility Principle (SRP) if I put "data access" methods on the business object? My gut feeling is the API feels more user friendly if the Load method is present on the class itself rather than having to guess which class the method happens to be in? Example: public class Image { public static Ima...

Is OO design's strength in semantics or encapsulation?

Object-oriented design (OOD) combines data and its methods. This, as far as I can see, achieves two great things: it provides encapsulation (so I don't care what data there is, only how I get values I want) and semantics (it relates the data together with names, and its methods consistently use the data as originally intended). So where...

Setters for collection type properties

Are setters necessary for Collection Type Properties //Type 1 class Company { private IList<Customer> customers; public IList<Customer> Customers { get { return customers; } set { customers = value; } } } //Type 2 class Company { private readonly IList<Customer> customers = new List<Custo...

Java class confusion

The word 'class' is used very loosely in Java tutorials and study material. There are many many different meanings to this word. Can some body please enumerate and explain all meanings of this word. E.g.: 'class' means an object, 'class' is an file extension, 'class' is the first word used in declaring object, etc. ...

Why is MATLAB reporting my variable uninitialized?

I made a class and in one of its methods I needed to calculate the distance between two points. So I wrote an ordinary function named "remoteness" to do this for me. Compilation Error: At compilation, "remoteness" was determined to be a variable and this variable is uninitialized. "remoteness" is also a function name and p...

Returning google.visualization.DataTable from Javascript Function

I'm working on a page that brings in various data from a google spreadsheet, and need to loop in order to draw multiple visualizations from multiple queries. In order to do this I'd like to run a loop which queries the spreadsheet alters returned data to fit my needs graphs the altered data. I've tried multiple techniques, after alt...

Are static inner classes a good idea or poor design?

I'm find I have several places that having public static inner classes designed that extend "helper" classes makes my code a lot more type safe and, in my opinion, readable. For example, imagine I have a "SearchCriteria" class. There are a lot of commonalities for the different things I search for (a search term and then a group of searc...

How Does a Login system generally work with OOP?

Sorry if this is a badly formed question, but I'm trying to make my web applications (using PHP) more OO. *EDIT* I'm developing the Framework myself */EDIT* Everything is great so far, I've made a Front Controller system that taps into a MVC system. The FC figures out what page you want, loads the specific page Controller (*EDIT* which e...

Lightweight PHP library alternative to common MVC frameworks

Hi hi, I'm looking for a easy to learn php library to use for my coming web app project. I've recently finished a web app with fully handwritten raw php code and it's absolutely hard to be done again for another project. even though I have the recent project code snippets to be used again, but due to their non-structural arrangement (not...

Law of demeter or return the whole vector

Which one is better: public: const vector<int> & GetPointsVector(); private: vector<int> PointsVector; Or: public: int GetCurrentPoint(); void MoveToFirstPoint(); void MoveToNextPoint(); bool IsAtLastPoint(); size_t GetNumberOfPoints(); private: vector<int> PointsVector; ...

Class Diagram for classless PHP application

Hello all, I have PHP application that is completely procedural (No PHP Classes). In my case, is there any formal diagrams I can draw to show how my web application that is equivalent to a UML class diagram for OOP based applications. Thanks all ...

A Guide for Creating your own Library for Cocoa(touch) development

I'm currently using a lot of the same subclassed objects with custom methods. It would be more convenient to create my own library which I can use for several projects. The goal is to have my own classes being available in the same way classes like UIView, CGRect etc are, including convenient methods like CGRectMake, both with classes ...

Casting between parent and child classes in delphi.

I'm writing some software that targets two versions of very similar hardware which, until I use the API to initialize the hardware I'm not able to know which type I'll be getting back. Because the hardware is very similar I planned to have a parent class (TParent) that has some abstract methods (for where the hardware differs) and then...

What's the difference between an interface and an abstract class?

Duplicate: When to use an interface instead of an abstract class and vice versa? Probably one of the most famous software developer job interview questions. What would be your answer? EDIT: I'm trying to find out how you would answer this in a real-life situation. Please try to formulate your answer as you would on a real job int...

Do I need an abstract class or interface here (or neither)?

I have a warehouse. Sometimes I want to lookup a box location by a name, sometimes by a description, sometimes by a UPC, maybe something else, etc. Each of these lookup methods call the same various private methods to find information to help locate the data. For example, upc calls a private method to find a rowid, so does name, so do...

What do you call a method of an object that changes its class?

Let's say you have a Person object and it has a method on it, promote(), that transforms it into a Captain object. What do you call this type of method/interaction? It also feels like an inversion of: myCaptain = new Captain(myPerson); Edit: Thanks to all the replies. The reason I'm coming across this pattern (in Perl, but relevant a...

Does PowerShell support OOP?

What is about such concepts as Class, Interface, Mixin in PowerShell? Does it support OOP? If so, where can I read about this? ...

Where should validation logic be implemented?

When developing my interfaces (contracts) and the concrete implementations of them, both the data models as well as repositories, I find myself questioning where the validation logic should go. Part of me (which tends to win out) says that the class itself should be responsible for it's own validation (string max length, date buffers, e...