oop

What is Delegate?

I am confused that what is the actual role of a delegate? I have been asked this question many times in my interviews, but I don't think that interviewers were satisfied with my answer. Can anyone tell me the best definition, in one sentence, with a practical example ? Thanks ...

Is there a common design pattern for making a collection class page-able?

I've run across this design issue a number of times and was wondering if there is a common OOP design pattern that addresses it. Design Issue: I need to implement a class that represents a collection of objects that can get quite large. For performance reasons, the presentation layer will present the data in individual pages requesting...

Is this how you go about calling your Dao's in your service layer?

In your service layer, say you have a method that does XX, is this how you would reference your Dao classes? public class SomeServiceImpl implements SomeService public void DoSomething(int someThingId){ UserDao userDao = this.daoFactory().GetUserDao(); SalesDao salesDao = this.daoFactory().GetSalesDao(); .. .. ...

A method that returns bool, but loads multiple objects

I have a simple method that returns bool, but it internally loads various objects. I check for null for each, but it becomes very ugly. Is there a better way? public bool SomeTest(int id1) { bool result = false; User user = userDao.GetById(id1); if(user != null) { Blah blah = blahDao.GetById(user.BlahId); if...

PHP empty() on __get accessor

Using PHP 5.3 I'm experiencing weird / non-intuitive behavior when applying empty() to dynamic object properties fetched via the __get() overload function. Consider the following code snippet: <?php class Test { protected $_data= array( 'id'=> 23, 'name'=> 'my string' ); function __get($k) { return $this->_data[$k]; ...

PHP Socket accept_connection hanging

I recently found out that PHP not only has the fsock* functions, but also functions to create a server itself. I decided to experiment a little bit, and came up with this. Now, the problem is that it hangs on accept_connection() (due to the fact that it's waiting for a connection.) I found out that the solution is to use stream_set_block...

What's the most appropriate way to expose lists inside a class?

Imagine the following model: A Table has many Rows A Row has many Cells What would be the preferable interface to deal with these classes in a "object oriented way"? 1 - Provide access to the properties rows / cells (Not necessarily exposing the underlying data structures, but creating for example a class RowCollection...) my_table...

reflection or instantiation?

I want to determine if a class exists and whether or not it implements an interface. Both of the below should work. Which should be preferred and why? //check if class exists, instantiate it and find out if it implements Annotation if(class_exists($classname)){ $tmp=new $classname; if($obj instanceof Annotation) {//do somethi...

Is it worth to use prototype or should we use OOP for javascript?

I am a developer for sometime now, and for the past few years I am using prototype framework and it's implementation for OOP, to be used in Javascript. I've used jquery and some other frameworks as well. I 've been studying how js works and how differs from OOP, as it is a prototype oriented language. In my opinion is in fact a great co...

Wondering how to deal with nsnumber objects in an arithmatic operation

I saw this thread but wanted to confirm: http://stackoverflow.com/questions/1801197/how-to-convert-nsnumber-objects-for-computational-purposes So basically anytime you want to deal with these objects you have to unpack their ivars, and then pack them back up into new objects, presumably NSNumbers? That seems hella weak(and a large pai...

Why stick to get-set and not car.speed() and car.speed(55) respectively?

Apart from unambiguous clarity, why should we stick to: car.getSpeed() and car.setSpeed(55) when this could be used as well : car.speed() and car.speed(55) I know that get() and set() are useful to keep any changes to the data member manageable by keeping everything in one place. Also, obviously, I understand that car.speed() and car.s...

Plugin design, having circular dependency issues

I have an ecomm application in Project#1. I have a payment gateway implementation in Project#2 that references Project#1. It references interfaces so that the gateway is implemented to a contract. Now I need to actually use the implementation from Project#2 in Project#1. There is a circular dependency so it isnt' working as it is. W...

Zend framework query, add to string

Hi guys, let's say that I have: $query = $this->select() ->where('name LIKE ?','%something%'); ->where('section LIKE ?','%something%'); ->where('cars LIKE ?','%something%'); ............ ............ You get the point! But I want to add the where() clause to the qu...

Help in restructuring a project

I have a commerce application, asp.net mvc. I want it to be extensible in the sense others can create other payment providers, as long as they adhere to the interfaces. /blah.core /blah.web /blah.Authorize.net (Implementation of a payment provider using interfaces Ipaymentconfig and paymentdata class) Now the problem is this: /blah...

Pattern for XML Parsing in iPhone..

I have a web service which returns certain "models" of which are all defined by a class in objective-c. Calls to RESTful methods will return either a singular model XML or a list of model XML elements. <widget> <a>foo</a> </widget> or <widgets> <widget> <a>foo</a> </widget> .... <widget> <a>foo</a> </widget> </widget...

When to use Abstract Factory and when to use Factory Method?

Could someone give me clear samples on when it's best suit to use de AF rather than the FM design pattern? AF:Abstract Factory FM:Factory Method Best, ...

What are the major differences in object models of dynamic languages like Smalltalk, Ruby and Python

I dived into understanding the Ruby object model in the last weeks, and although so far was only a user of the fruits of ruby's and python's object in the past, I became curious how these things might differ in other languages. Years ago I touched smalltalk's squeak. Smalltalk is often figuring as a referential object oriented language,...

Which Design pattern

Hello I have a program which models manufacturing process. In each stage of the process , objects are created. Specific objects can be created only in certain stage . The objects created in later stage, are using the objects created in earlier stages i.e output of previous stage is input to later stage.Which design pattern to use to mod...

Problem with multiple instances of a function.

Hello, I have made a music quiz similar to the one in the iPod, everything runs perfect until my program calls a class MP3 ( http://pastebin.com/d52fe24ce ) to stop with the function close(). The problem in my case is that the MP3 is not "instantiated" when it is called. I am not sure but I think this is because the player I created is ...

Naming of types when using an ORM

I am working on a project where a number of types have the suffix "Instance". For example, we have the concept of tabs in the application, so we have a TabInstance type. To me this seems redundant and even confusing / wrong, as there is already the concept of an instance in OO terminology. The system uses nHibernate as an ORM - I wond...