oop

C# - Interface Clarification.

I read some points about interface: " Interface is the definition of contract that a class must conform.It does not inherit anything. " while defining the differece between interface and abstract class can i say : when a class is derived from abstract class it is known as real inheritance.When a class uses interface then it is not ...

problem with class method - cannot get it to work inside foreach loop - php

Hello, I wrote the class Link which has a method shortTolong() this should return the real URL for a shortend url by returning the 'location' response header. i tested it and it works OK here is the code public function shortTolong() { $urlMatch = array(); $ch = curl_init(); $options = array ( ...

Why and Where do we use down casting?

Are there any cases where we do down casting of objects? If we do, why? I have observed a way of hiding implementation using the below code. Is this the correct way to do? Is there any better way to achieve the same. class A{ public: A(); virtual ~A(); //exposed virtual functions }; class AImpl : public A{ p...

Class naming and namespaces

Will using same class name within multiple namespaces get me into trouble? I also try to remove dependency to math library. What do you think about following design. first file #define MATH_RECTANGLE_EXISTS namespace math { class Rectangle : Object2D { public: float perimeter(); float area(); float...

Is this C++ reassignment valid?

Sorry for the basic question, but I'm having trouble finding the right thing to google. #include <iostream> #include <string> using namespace std; class C { public: C(int n) { x = new int(n); } ~C( ) { delete x; } int getX() {return *x;} private: int* x; }; void main( ) { C obj1 = C(3); obj1 = C(4); cou...

OOP -Is Encapsulation a subset of Abstraction ?

As both encapsulation and abstraction relates to information hiding,can i mean encapsulation as a subset of abstraction? ...

JavaScript function encapsulation outside the object

Please see the following script: var x = function(param){ this.data=param; this.y = function(){ alert(this.data) } return this; } /* x.prototype.z = function(){ alert(this.data); } */ x(123).y(); x(123).z(); // This should behave same as y() When I call x(123).y() then message displays 123. ...

Injecting a resource into an abstract class

I have an abstract class, Shape, and I have a Canvas object that the Shape uses to set its position. I need to make sure that all Shapes have a Canvas object, preferably a Canvas object that is the same one across all shapes. I have thought of a couple of options: Add a canvas parameter to the Shape constructors (there are many) Havin...

Should I always use accessors for instance variables in Objective-C?

If I have a class with some IBOutlets, it seems kind of silly to create accessors for these. But then I feel like I'm breaking OO practices by not always going through the accessors for instance variables. I also feel the same way about some instance variables that should not be public, I'd rather not expose the inner workings of some ...

When to use run-time type information?

If I have various subclasses of something, and an algorithm which operates on instances of those subclasses, and if the behaviour of the algorithm varies slightly depending on what particular subclass an instance is, then the most usual object-oriented way to do this is using virtual methods. For example if the subclasses are DOM nodes,...

Managing inverse relationships without CoreData

This is a question for Objective-J/Cappuccino, but I added the cocoa tag since the frameworks are so similar. One of the downsides of Cappuccino is that CoreData hasn't been ported over yet, so you have to make all your model objects manually. In CoreData, your inverse relationships get managed automatically for you... if you add an ob...

Organizing Classes in PHP

Suppose I've the following classes in my project: class Is // validation class class Math // number manipulation class Now, if I want to validate a given number for primality where would be the logical place to insert my Prime() method? I can think of the following options: Is_Math::Prime() Math_Is::Prime() ...

Can web methods be overloaded?

I have built a regular .NET asmx service. How do i overload web methods in this service? ...

If not a singleton, then what?

So I'm working on a middleware layer. I'm consuming a COM DLL that deals with the low level hardware interaction, and providing an interface for the UI to do IO with the hardware. As part of the design of my layer, we put in a contextmanager that arranges the various pieces of hardware to produce contexts that our application can work ...

What does the variable $this mean in PHP?

I see the variable $this in PHP all the time and I have no idea what it's used for. I've never personally used it, and the search engines ignore the "$" and I end up with a search for the word "this". Not exactly what I wanted. So, can anyone tell me? ...

Can I use a C# collection to hold class instances with self-referential relationships?

Hi, I need to model in memory a collection web files, but that relationships between them. That is file A (e.g. html) may have a link to file B (e.g. css) and file C (e.g. javascript). Also file D may also require file B. If I wanted to delete file A I would need to make sure any files it uses (e.g. file B) is not also being used ...

downcast and upcast

I am new to C# (and OOP). When i have some code like the following: class Employee { // some code } class Manager : Employee { //some code } Question 1: if i have other code that does this: Manager mgr = new Manager(); Employee emp = (Employee)mgr; Here emp is a manager, but when i cast it like that to an Employee i...

Good resources for learning advanced OOP features in PHP 5?

I'm familiar with advanced OOP features like interfaces, abstractions, enums, generics, public , private , static keywords, exceptions, etc from Java. However, I'd like to know how all these things translate to PHP. Specifically I'd like one tutorial or website which goes through all the advanced OOP features of PHP which were added in ...

Why does PHP 5 use __contruct() instead of className() as constructor?

Why should I usefunction __construct() instead of function className() in PHP 5? ...

A method that iterates over the passed in objects properties

Trying to figure out how to create a method that will iterate over the properties of an object, and output them (say console.writeline for now). Is this possible using reflection? e.g. public void OutputProperties(object o) { // loop through all properties and output the values } ...