oop

Is there a way to reassign $this?

Hello, First of all, I do not want to extend a class. I would ideally like to do this. public function __construct() { /* Set Framework Variable */ global $Five; $this =& $Five; } I have a system where the variable $Five is a container class which contains other libraries. I could assign this to a local variable of Five... i.e. p...

Correct interface use with Entity Framework / Linq-to-SQL

I'm about to show my inexperience here, but hey - like any developer I want to learn. Given the following interface: public interface IRepository { entityDB Database { get; set; } IQueryable<T> All<T>() where T:class, new(); T Single<T>(Expression<Func<T, bool>> expression) where T : class, new(); IList<T> Find<T>(Expr...

How do I call an instance method from another classes' static method (i.e. have only one object)?

Hi all, my form1 class contains a bunch of data that I need to save, so there should only be one instance of it running at a time. public partial class Form1 : Form { public string form1string = "I really need to save this data"; public Form1() { InitializeComponent(); // Even if I pass my form1 object he...

Object oriented programming , inheritance copy constructor

Suppose i have a base class "person". and i publically inherits a class "student " from the base class "person". i have not written the copy constructor for base and the derived class. now suppose i write in the main program main() { student sobj1("name", "computer science"); student sobj2=sobj1; } now in the second line the default ...

What will be the memory allocation of this C#.NET code.

using System; class ClassOfInts { public int x; public int y; } class Test { ClassOfInts objClassOfInts; string name; public TestMethod(int p, int q, string s) { objClassOfInts=new ClassofInts; objClassOfInts.x=p; objClassOfInts.y=q; name=s; } } class Main { static Ma...

Using DLLImport to import an Object

I have a dll for a c++ class (SLABHIDDevice.dll). I am trying to use the functions of this dll in a C#.net application. The dll contains several methods which I can use easily with statements such as this... (I appolagize if i get some of the terminology wrong here I am new to using dlls) [DllImport("SLABHIDDevice.dll")] publi...

php code is not executing?

<?php class abhi { var $contents="default_abhi"; function abhi($contents) { $this->$contents = $contents; } function get_whats_there() { return $this->$contents; } } $abhilash = new abhi("abhibutu"); echo $abhilash->get_whats_there(); ?> i've initialized variable contents a default and a...

Python class methods

Hi I have a class as follows: class X: def __init__(self): self.sum_x =0.0 self.sum_x_squared=0.0 self.var_x =0.0 self.sum_y =0.0 self.sum_y_squared=0.0 self.var_y =0.0 def update(self,data): [x,y,vx,vy]=data self.update_sums(self.sum_x,self.sum_x_sq...

Inheritance and interfaces .NET

Quirky question: Imagine that I have a base class called BaseFoo. I have an interface with some methods called IFoo. And I have tons of classes beneath BaseFoo. If i implement the interface in BaseFoo, i dont need to implement in the inherited classes, correct? Ok, but imagine that i have a generic function that will treat IFoo's. Do ...

Wrapping a nested collection

Hi, I'm currently working on a wrapper for a third party component (not the best idea, I know) that we just purchased, a grid to be precise. Well, exposing most of the grid properties hasn't been that hard so far... my real issue is with the rows/cells collection. The seniors/leads don't want the developers going crazy with everything...

Composition vs. Inheritance: Is the need for mutual referencing a good hint?

If two classes both need to know about each other to do their job, i.e. class A must maintain a reference to class B and class B must maintain a reference to class A, is this generally a sign that inheritance would be a better idea than composition, provided you aren't violating the Liskov Substitution principle? My thinking is that thi...

OO: Should you access your private variables through properties inside your class?

I was wondering, what is good practice: private int value; public int Value { get { return this.value; } } private int DoSomething() { return this.Value + 1; //OR return this.value + 1; } So, the question is about how you should treat your class variables. Should you access them through your properties or just...

General Objective-C Class method question

I have an iPhone application which has some methods to gather information from the web and which then creates an object, which holds this information as properties (lets say I'll get objects of type x). Since I might need those kind of objects from various points within the application, I put the method to create one instance of the obje...

private vs public inheritence

I have a question based on this question In the section http://www.parashift.com/c%2B%2B-faq-lite/private-inheritance.html#faq-24.3 the following is mentioned: A legitimate, long-term use for private inheritance is when you want to build a class Fred that uses code in a class Wilma, and the code from class Wilma needs to invoke mem...

difference between php and php5

i want to study oops related php, mainly for mashups and some development. I started with php n mysql, whats main relation or difference b/w php and php5. Is there anything like different php for web development and other php for software development?? guide me some books with php oops examples and concepts......... ...

OOP Difference between a derived class and an inherited class?

From an OOP point of view is there any difference between a derived class and an inherited class? Or is it simply terminology? ...

PHP Access sub property by name at runtime

Hello! Is it possible to access a sub-property of an object dynamically? I managed it to access the properties of an object, but not the properties of a sub-object. Here is an example of the things I want to do: class SubTest { public $age; public function __construct($age) { $this->age = $age; } } class Test...

Functional programming vs Object Oriented programming

I'm an Object Oriented programmer looking forward to learning a functional language. My questions are: When do you choose functional programming over object oriented ? What are the typical problem definitions where functional programming is a better choice? ...

What is the real significance(use) of polymorphism.

I am new to OOP. Though I understand what polymorphism is, but I can't get the real use of it. I can have functions with different name. Why should I try to implement polymorphism in my application. ...

When should I use static methods in a class and what are the benefits?

I have concept of static variables but what are the benefits of static methods in a class. I have worked on some projects but I did not make a method static. Whenever I need to call a method of a class, I create an object of that class and call the desired method. Q: Static variable in a method holds it's value even when method is exec...