oop

Where to expose the results of a specific SQL query in the domain model.

Hi - Which of these examples would be the best way to expose a collection of Orders for a specific Person that contain a specific Product and why? Or maybe there is a better way to do this alltogether? (Sorry I am new to domain modeling). The Orders list is pulled from the database with an SQL query and turned into a List collection. A ...

How to manipulate this interface?

I have seen lots of kinds of interface to multithreading and locks. These make me feel frustrating, Some of them include 2 different classes like the sample below, while others have only one class and the acquire() can implement the wait function. My questions are: Why we design locks like this in object oriented programming? How t...

Variable scope for PHP callback functions

Hi, In response to another question I asked about regular expressions, I was told to use the *preg_replace_callback* function (http://stackoverflow.com/questions/959017/) as a solution to my problem. This works great, but now I have a question relating to variable scope in callback functions. The function that parses the text is part o...

How do I add a parameter in a callback function using prototype.js ?

Hi, Using prototype.js, I create a custom object which is going to be a parameter on a constructor : var options = Object.extend({month: date[0], year: date[1], day: date[2], oncalchange: update}); // update is defined like that : var update = function(d){ // b...

When class B inherits from class A, must it be that "class B is-a class A"?

In a book, it says the class Name has the property of last name and first name. Address inherits from Name, and has additional property of street number, street name, city, state, zipcode. That seems different from the other cases, where Cat inherits from Animal, and Cat "is-a" Animal. Is this "is-a" relationship requi...

How many kinds of lock are there which can be used to design?

In a program, I can design lock to threads,lock to object or files. Are there difference between these locks? If yes, how many kinds of lock are there which can be used to design? Are there some tutorials to design locks in object-oriented programming? ...

oo question: applying same logic to 2 similar objects

I have 2 objects to create that are identical except for that they refer to my dev and test WCF services. Basically, these are the object for the service itself, and the object for a DTO created by the WCF data-contract. In my test client, I create either the 2 objects related to the dev WCF service, or the 2 objects related to the tes...

Object relationships

Suppose you have two objects, Person and Address and they have a relationship, that is a Person has an address. Obviously the person object has a reference to the address object but does the address object really have to know about the Person object? What gives that it has to be a two way relationship? Thanks! ...

How could you improve this code design?

Lately, I've been making use a lot of the Strategy Pattern along with the Factory Pattern. And I really mean a lot. I have a lot of "algorithms" for everything and factories that retrieve algorithms based on parameters. Even though the code seems very extensible, and it is, having N factories seems a bit of an abuse. I know this is pre...

Creating a trouble shooting web page with a series of ?s in asp.net. Directed Graph

I've been working on my first web page which will be used as a trouble shooting guide based on a series of questions. The questions are determined by the answer of the previous question, so it turns into a "choose your own adventure". Luckily I was given a decision flow chart showing all the possible paths, but it looks like the Tokyo ...

Polymorphism with Database Query

I am designing a dashboard to display corporate metrics (currently with ASP.net 3.5 in C#), and looking for advice on design. I'm not as used to OOP in web applications. There may be many different metrics that can be seen by different users in a Many-to-Many relationship. I am storing the users in a local SQL database and it of cours...

Why does C# take value from overridden property instead of the overriding property?

I would suspect the code below to output: (I am a SmartForm object and using the method in SmartForm).xml instead, however, it outputs: (I am a SmartForm object and using the method in Item).xml Why is that? How can I force C# to take the value from the overriding property? That is why I am overriding the property. using Sys...

Code Examples - the logic layer and service

Hello, I am looking for sample projects/ project templates. which show an N-Teir application (perferably in C# but do not mind Java). so far i have found the following: S#arp Architecture - which i think is awesome DotFactory Patterens in Action - I have the .Net 2.0 copy, exellent, but it only shows crud do you know any samples whi...

What is the difference between extending a class and including it in PHP?

Can someone explain to me what the difference between include_once 'classb.php' class A { $a = new B } and class A extends B { $a = new B } is? What advantages/disadvantages are there to extending a class vs. including the .php file? ...

Extra public methods in derived classes?

If I have an abstract class and derived classes of that class, am I correct that, according to good and practical design practice, that the derived classes should not provide extra public methods (they should only implement abstract classes and optionally override parent methods)? Furthermore, is it acceptable practice to have a differe...

Where should my method go

I have a class that represents a row in a table. I want to add a function that manipulate the data in the row. Where should I add the function? 1) inside the class because it is related to the class 2) outside the class in a separate helper class? In the past I would have always picked number 1. I am starting to think that number 2 ...

Interface should not have properties ?

My office colleague told me today that is bad practice to use properties in interfaces. He red that in some MSDN article(s), which I couldn't find (well I was trying few times on google, probably with wrong key words). He also told me that only methods should be in interface. Now, I am aware that is is not strict rule, since obviously in...

Enforce service layer business rules on entity property changes, or hide entity property from clients but not service?

Let's say I have a class Customer, which has a property customerType. I have another class called something like SpecialContract, which has a Customer and some other properties. If customer.customerType == SPECIAL, then there is a SpecialContract which has a reference to this particular Customer. Now I realize that this is a bit hoaky...

When to Be Specific About the Type of List You Want

Let's say I have a class which, internally, stores a List of data: import java.util.List; public class Wrapper { private List<Integer> list; public Wrapper(List<Integer> list) { this.list = list; } public Integer get(int index) { return list.get(index); } } For the sake of this example, pretend it's a usefu...

Why in java functions are written virtual by default and c# nonvirtual?

Hi, Why java functions are virtual by default.But c# its the oposite. Which is better?Or what is the advantage and disadvantage in both? Thanks SC ...