oop

Method Chains PHP OOP

Hello, After seeing another question just started, I wanted to ask as to how something is actually achieved. When I use some frameworks they do this like $object->select('something') ->from('table') ->where( new Object_Evaluate('x') ) ->limit(1) ->order('x'); How do you actually do this kinds of chains...

C# has abstract classes and interfaces, should it also have "mixins"?

Every so often, I run into a case where I want a collection of classes all to possess similar logic. For example, maybe I want both a Bird and an Airplane to be able to Fly(). If you're thinking "strategy pattern", I would agree, but even with strategy, it's sometimes impossible to avoid duplicating code. For example, let's say the foll...

Modifying type-specific properties in implementation of interface

I know this is a silly question, in that the answer is likely an "oh right, of course!" one. Here is what I have: public interface IEvent { int Id string Title } public class MeetingEvent : IEvent { int Id string Title //Meeting Properties string Room; User Organizer; } public class BirthdayEvent : IEvent { int Id ...

Modules vs. Classes and their influence on descendants of ActiveRecord::Base

Here's a Ruby OO head scratcher for ya, brought about by this Rails scenario: class Product < ActiveRecord::Base has_many(:prices) # define private helper methods end module PrintProduct attr_accessor(:isbn) # override methods in ActiveRecord::Base end class Book < Product include PrintProduct end Product is the base cla...

Where should I store virtual/calculated/complex object fields in my models?

I have models corresponding to database tables. For example, the House class has "color", "price", "square_feet", "real_estate_agent_id" columns. It is very common for me to want to display the agent name when I display information about a house. As a result, my House class has the following fields: class House { String color; Do...

What functionality to build into business objects?

What functionality do you think should be built into a persistable business object at bare minimum? For example: validation a way to compare to another object of the same type undo capability (the ability to roll-back changes) ...

What is the best authentication script?

Hi, I'm planning on making some dynamic PHP websites and I need a free Authentication system that allows me to create control panel for these sites' admins. It should contain : Remember password Lost password Maximum login attempts per specific interval users Management Thanks. ...

How to quickly determine if a method is overridden in Java

There is a possible optimization I could apply to one of my methods, if I can determine that another method in the same class is not overridden. It is only a slight optimization, so reflection is out of the question. Should I just make a protected method that returns whether or not the method in question is overridden, such that a subcla...

PHP SESSION: SESSION Variables Automatically Reset after Unserialize()

I am testing codes from build internet which is a tutorial of OOP. I got a error message: unserialize() expects parameter 1 to be string, object given in includes/global.inc.php on line 20 Here is the code of serialize(): $_SESSION['user'] = serialize(new User(mysql_fetch_assoc($result))); And here is the code of unserialize...

Is there any PHP Object Oriented Programming in Practice Tutorial?

Hi there I've learning PHP for a while, and also have read some OOP tutorials. I tried to start my own website using OOP PHP but I got quite lost. I am not sure what to do in real project. I think maybe I need some practice tutorials, which is talking about real projects. I tried to read some code of PHP framework like CodeIgniter, bu...

Neat way to have javascript function return status based on PHP variable?

In a CMS I'm building I want to have my own javascript namespaced object $cms. This object should have a method/function hasIdentity that returns the status of whether the user is logged in. Is there a way that I can have this method/function return the status without having to resort to either: AJAX a global var or rewriting the fol...

How to relate Customer and Payment Details

Hello Everybody, I have a query related to relation between objects. Scenario: Payment Details - a. Credit Card b. Saving Account c. Cheque Now, a customer should have any of the above payment detail before buying any product. How do i relate payment detail with customer. Can any one explain with example... Thanks in advance. ...

Newbie polymorphism question using generics

I have the following method that takes in a details object, validates it, converts it to a request and enqueues it. Everything is fine apart from the validate request which I am having trouble with. Basically, there is different validation logic for each different details object. I know from the generic constraint that the details object...

Creating objects from their description

I need to create objects by reading their description from a text file. The objects are also in a hierarchy or can be decorative objects For example For this descrition in a text file: Sample.txt A FileReader "fileName.txt" A Buffered FileInput reader "FileName.txt" A Buffered StringInput reader "TestString" The program should ...

Resources for evidence-based development practices

I am interested in studies and papers detailing trials that explore the evidence for different development practices in object-oriented languages. I am particularly keen on studies that measure productivity or consider the influence of modern IDEs. Can you point recommend any good resources for this? Has much work been done in this area ...

Generic Singleton<T>

Guys, I have a question, is this the correct approach to make a Generic Singleton? public class Singleton<T> where T : class, new() { private static T instance = null; private Singleton() { } public static T Instancia { get { if (instance == null) ...

Java Object Oriented Design Question: update internal state or return new object

This is a design question. The design is pseudo-code and represents a small example but I may add a lot more methods, data, logic in the future. In this example, I am considering two approaches. In the execute method below, should I return an immutable "data/bean/model" object with the output of the execute method or update the state ...

When do you need to create abstractions in the form of interfaces?

When do you encourage programming against an interface and not directly to a concrete class? A guideline that I follow is to create abstractions whenever code requires to cross a logical/physical boundary, most especially when infrastructure-related concerns are involved. Another checkpoint would be if a dependency will likely change i...

Designing a CAD application

Hi, I am designing a CAD application using a variation of MVC architecture. My model and view are independent of each other. They communicate through the controller. My problem is if I need to draw an object (say line or polyline) I need a number of input points. What would be the best way to get the points? All the events from the view ...

Class design suggestions: extending a class and code reuse

The gist of this question is about extending a class, minimizing jam-packing everything into a single class, and maximizing code re-use. After reading this question, please feel free to edit the title or description to make it more succinct. Though the post looks long, I am just trying to be thorough by using a lot of examples. Suppose ...