oop

Is it poor design to have a class used only by one other class?

I have a QueueProcessor class that processes a work queue. I want to send an email out of a summary of all work done with a bunch of statistics. I am already using a mail class (Zend_Mail), so most of the email work is abstracted away for me, but I still have to figure out where to put the code to generate the summary information. I'm ba...

When implementing dependency injection, should exceptions be injected?

My team is muddling through implementing dependency injection in a PHP project using a homebaked DI container. Our first iteration of DI was perhaps taken to the extreme, and even exceptions are being injected into classes that depend on them. Is this a good practice or overkill? ...

Preventing an object from being altered after it enters a certain state? (C#)

I have a use case that I've never really dealt with before. I have an object that after the user clicks "Save" should not be changed. Initially I created two objects, DraftObject and SavedObject. For the latter I created a constructor that only accepted the DraftObject and set each property as protected set. This works but does not seem...

How can I improve this php code

Hi, I have a txt file that gets loaded and printed using a class. I'm relatively new to php, so I wonder if the class can be improved and some of the duplicated code (when printing the change-log) can be removed. Here is the class : class changesHandle { public function load($theFile, $beginPos, $doubleCheck) { // Open f...

How to model subclasses with different types of the same property in a language without generics?

I have 3 types of objects: Red, Green, and Blue. I have 3 kinds of devices that handle each type of object, respectively. No device can handle more than 1 type of object. Each "object handler" has a reference to an object which it is currently handling. In Java I'd do something like this: public class RedObject {} public class GreenObj...

Problem with objects in php

Hi. I am trying to get used to writing object oriented, but often I get a little stuck. I have this queries that I want to use to create arrays. $user1 = mysql_fetch_object(mysql_query("SELECT * FROM tbl WHERE username='$oc->user1'")); $user2 = mysql_fetch_object(mysql_query("SELECT * FROM tbl WHERE username='$oc->user2'"...

Good book on Large scale Object Oriented System Design in C++

I am specifically looking for book which discuss about large scale system design (like Oracle server, Web servers) with extensive use of design patterns and meta programming (templates) in C++. thank you, ...

C++ polymorphism - Auto detect derived type

I have certain code that I want to optimize. It looks like this: function abc( string format ) { if (format == "a") { // this is a string, I shouldn't have used single quote, sorry for the confusion classx::a t; doit(t); } if (format == "b"){ classx::b t; doit(t); } if (format == "c"){ classx::c t; doit...

how to assign a value to another class's initialize parameter from child class in Ruby

How do I assign a value to another class's initialize parameter in Ruby class Ubac def initialize(p_str) @p_str=p_str (.....) end def method1 (.....) end end class ReqQuote < Ubac def initialize(p_code) @code=p_code # here how do i initialize the @p_str to the value which is returned from the get_data m...

Create object for generic objectlist

I'm not sure if this is possible in Delphi. I've looked around and can't seem to find an answer (Example or inidaction that it's not possible): I have a generic list class, and I want to create an instance of the generic type. For example: type TTypeA = class(TObject); procedure Test; var MyList: TobjectList<TTypeA>; NewListObje...

How do I select a member variable with a type parameter?

Hi, I have a cache object that caches a number of different types of objects, as illustrated below: class Cache { public: ObjectTable<ObjTypeA> m_objACache; ObjectTable<ObjTypeB> m_objBCache; ObjectTable<ObjTypeC> m_objCCache; }; The (horrible) way I'm currently using the cache at the moment is directly accessing the cache...

C++ - How to call creator class/object

Hi guys, I need to call properties and functions of an object from a different class. The idea is passing 'this' as a parameter to the other class constructor. E.g.: instance = ClassName(this); And then do: ParentClass parentInstance; ClassName::ClassName(MainApp _instance){ parentInstance = _instance; } However, my compiler ...

overriding a method in R, using NextMethod

how dows this work in R... I am using a package (zoo 1.6-4) that defines a S3 class for time series sets. I am writing a derived class where I want to override a few methods and can't get past this one:[.zoo! in my derived class rows are indexed by timestamp, like in zoo, but differently from zoo, I allow only POSIXct values in the in...

What is 'exceptional'?

I'm looking for a definition of 'exceptional' in terms of unit testing or OOP principles. Several times on SO when talking about exception throwing, I've seen comments like, "Well, I wouldn't consider getting Foo from Bar to be exceptional." (Is there a trollface emoticon?) I did some googling and an answer wasn't immediately forthcomi...

Share instance data across objects/classes in a custom web app

I'm working on a rack web app from the ground up in Ruby and I want to be able to share the instances of several objects across all classes in the app. For example, the logger, the request information, a currently authenticated user, get/post parameters, etc. To any of you familiar with PHP, I've accomplished this in the past with stati...

Javascript Objects and jQuery

I'm not sure what the best way to approach this is. I have a control that I want to be able to open and persist some data or change it on the fly. function TaskControl(params) { this.params = params; this.openTaskControl = function () { alert("openTaskControl"); } $("#button").click(function () { this....

Does every user defined class needs to implement IDisposable interface to get garbage collected

I am not sure how the user defined class objects are garbage collected. Do I need to implement IDisposable interface on every class and call the dispose() method on it to free the memory? ...

Gradual migration to a new database schema. ¿Suggestions?

(This question is about the best way to temporarily and programatically keep new records of two databases in sync, having very different schemas, and ignoring the old -outdated and no longer required- records.) I work on a company that provides TV programming information for guides, newspapers and websites. I have an old system that ha...

How do I model an object to track equipment / assets over time?

I've been trying to figure out the best way to model this entity, and I'm getting stuck. Here's the basic use case/story: We have equipment arriving on site. We won't know what the equipment is until it arrives. Once the equipment arrives on site it must be recorded as having arrived and whether it was idle or active. If it is active th...

PHP Error: "Call to undefined function AddUser() ". What am I doing wrong?

Code: http://pastebin.com/h8WuYbJn Full error: Fatal error: Call to undefined function AddUser() in C:\xampp\htdocs\scripts\steam.php on line 37 What exactly am I doing wrong? Everything should be right, but it isn't (at least according to PHP). ...