oop

Best practice: Adding child node to a parent in child constructor or not?

I'm working with some code that adds a child node to it's parent in the child's constructor. The code looks something like this: Class: class Node1 { public Node1(Node1 parent, String name) { if(parent != null) { parent.add(this); } this.parent = parent; } private void add(Node1 child) { children.add(ch...

Design patterns used in Gmail's JavaScript?

Can anyone tell me what design patterns (if any) were used when building Gmail? I understand the concept behind it - queue up some requests, increment the bar when each completes, init the display when all are down - but I'm specifically interested whether there's a specific design pattern I can use to mimic the features. ...

Inheritable only inside assembly in C#

In C# Is there way to specify a class to be inherited only by a class present in the same assembly and for other assemblies should behave like a public sealed type. ...

How to prepare for a interview test in understanding foreign source code?

Hi, recently I had a job interview where I had to present self-written code and explain the programm architecture and design, had to take a look at company source code, explain what I understand of this source code sections presented (it was the domain model of an application) and had to modify the code to let the program work a little...

Why are public fields faster than properties?

I was poking around in XNA and saw that the Vector3 class in it was using public fields instead of properties. I tried a quick benchmark and found that, for a struct the difference is quite dramatic (adding two Vectors together a 100 million times took 2.0s with properties and 1.4s with fields). For a reference type, the difference doesn...

Logic is now Polymorphism instead of Switch, but what about constructing?

This question is specifically regarding C#, but I am also interested in answers for C++ and Java (or even other languages if they've got something cool). I am replacing switch statements with polymorphism in a "C using C# syntax" code I've inherited. I've been puzzling over the best way to create these objects. I have two fall-back meth...

Determining type on the fly in OCaml's OOP construct

I am learning about OCaml's OOP constructs and partially implemented this today until I realized I have no idea how to represent a polymorphic match statement without using the type keyword outside of the object. class bar (param:string) = object (code) end;; class foo param = object (code) initializer match param with string -...

What is serialization?

Hi I am getting started with OOP programming and would like to know what is the meaning of serialization in OOP parlance? I am not a native english speaker hence the question. ...

In MVC, where is the correct place to put authorization code?

In MVC, where is the correct place to put authorization code? The controller? The Model? In the view? All over the place? ...

A brilliant example of effective encapsulation through information hiding?

"Abstraction and encapsulation are complementary concepts: abstraction focuses on the observable behavior of an object... encapsulation focuses upon the implementation that gives rise to this behavior... encapsulation is most often achieved through information hiding, which is the process of hiding all of the secrets of object that do no...

is placing Entity in the name of a Domain Class a good practice?

currently i am discussing if placing entity at the end of each entity is a good practice for example public class CustomerEntity:BaseEntity{} instead of public class Customer:BaseEntity{} in my career i had seen both, but how do you do it nowadays? ...

Best way for many classes to reference a database connection class

I'm soon going to be starting the development stage of my coursework and the current design is to have a single class that handles database connections and many classes that call it; the database class is supposed to open the connection and pass queries along blindly, other classes are responsible for the contents of those queries. Wha...

PHP: Outlook style rule engine

I am trying to construct a rule-based system for interpreting data. However, I am having issues deciding on a way to construct the logic for storing and interpreting rules. Currently, there is a database structure that quite complex, but will deal with all aspects of storing the rule data. The idea is that the system will be able to mim...

Why are interfaces preferred to abstract classes?

I recently attended an interview and they asked me the question "Why Interfaces are preferred over Abstract classes?" I tried giving a few answers like: We can get only one Extends functionality they are 100% Abstract Implementation is not hard-coded They asked me take any of the JDBC api that you use. "Why are they Interfaces?". C...

Separation of concerns; MVC; why?

I'm currently reading up on OO before I embark upon my next major project. To give you some quick background, I'm a PHP developer, working on web applications. One area that particularly interests me is the User Interface; specifically how to build this and connect it to my OO "model". I've been doing some reading on this area. One of...

Inheritance & Events

Hello everyone I have an interface defined like so: public interface IRipper { IRipperHost Host { get; set; } void Rip(FileStream stream); event RipperEventHandler OnStart; event RipperEventHandler OnComplete; event RipperEventHandler OnProgressChanged; } public delegate void RipperEventHandler(object send...

How do you make one generic select method for your DAL ?

Scenario You have an Assembly for Data Transfer Objects containing 10 classes that exactly represent 10 tables in your database. You generate / build a DAL layer that has methods like - DTOForTable1[] GetDataFromTable1(); DTOForTable2[] GetDataFromTable2(); and so on.... Question How do I make a method that hides the numerous...

Who should a method belong to?

I'm trying to design a simple game ---Pong, Arkanoid--- using strictly "Proper OO", whatever that means. So, by designing myself to death, I'm trying to get to a point where I'll know what to do or not do next time... Who should handle, for example, colissions? And scorekeeping? My first idea was giving a couple jobs to the ball, but ...

Accessing a class that has been instantiated by a method within a separate class

In a nutshell: how do I access the methods of a class that is instantiated by a method of a different class? There is a bit of code I am looking at right now that does the following (altering the code is not an option, btw. It isn't mine... I'm just decipher it): A class has a method that instantiates a different class. It looks someth...

What's the difference between data and code?

To take an example, consider a set of discounts available to a supermarket shopper. We could define these rules as data in some standard fashion (lists of qualifying items, applicable dates, coupon codes) and write generic code to handle these. Or, we could write each as a chunk of code, which checks for the appropriate things given th...