oop

Parameters implementing a certain interface and having a specific superclass: generics or instanceof?

I would love some help on a particular design. This is the code I wish worked: abstract class Square {...} abstract class Circle {...} interface JPGExportable {...} class SquareJPG extends Square implements JPGExportable {...} class CircleJPG extends Circle implements JPGExportable {...} interface Interface { draw(Square square);...

PHP: Variable scope in OOP?

Hi everybody, Here's my code: class Manual extends controller { function Manual(){ parent::Controller(); $myVar = 'blablabla'; } function doStuff(){ echo $myVar; // Doesn't work. } } I've tried various methods to make it work, but I've can't get my head around it. What can I do? Thanks ...

OOP duplicate extends

I have two classes which both extend from SQL class like this: class SQL { private $db_connect_id; function connect($ad, $db, $us, $pa){ $this->db_connect_id = mssql_connect($ad, $us, $pa); mssql_select_db ($db, $this->db_connect_id) or die('sql error'); } function sql_query($query = ""){ ...

How should i refactor this?

so in my application I've got several different customers being "serviced". Each customer has their own implementations of various classes that are all based on interfaces. With the latest customer being added, I've noticed there will be a lot of duplication of code from another customer but the other customer is in no other way relate...

Is there a better/cleaner way to conditionally create a type than using instanceof? [Java]

Suppose I have: public class FightingZone<MobileSuitso, Background> { private MobileSuitCollection<MobileSuitso> msCollection; private BackgroundInfo<Background> bgInfo; public FightingZone(MobileSuitCollection<MobileSuitso> newCollection, BackgroundInfo<Background> newInfo) { this.msCollection = newCollection; ...

Possible to return instantiator in Python?

class Parent(): def __init__(self): self.child = Child() class Child(): def __init__(self): # get Parent instance self.parent = self.Instantiator() I know this isn't proper encapsulation but for interest's sake... Given a "Parent" class that instantiates a "Child" object, is it possible from within Child to return the...

Javascript inheritance - instanceof not working?

I'm writing a simple platform game using javascript and html5. I'm using javascript in an OO manner. To get inheritance working i'm using the following; // http://www.sitepoint.com/blogs/2006/01/17/javascript-inheritance/ function copyPrototype(descendant, parent) { var sConstructor = parent.toString(); var aMatch = sConstruct...

Magento: Image not found when I change the values passed into the resize() function.

if I change this: $this->helper('catalog/image')->init($_product, 'small_image')->resize(80, 80) to this: $this->helper('catalog/image')->init($_product, 'small_image')->resize(180, 180) The image cannot be found, does anyone know why this is? ...

how to copy properties of a jlabel to another new jlabel

I want to copy my private jlabel object to a new jlabel object and make the new one public. Idea is to allow anyone to access jlabel's properties but not to allow make any changes that will be displayed on the original interface. Below code doesnt work as it simply copies the reference of the original object. public javax.swing.JLabel g...

Are global static classes and methods bad?

It's generally agreed upon that relying heavily on global stuff is to be avoided. Wouldn't using static classes and methods be the same thing? ...

Java inheritance appending a function instead of overwriting it

public class Cls1{ public foo(){ doX(); } } public class Cls2{ public foo(){ doY(); } } Cls2 cls = new Cls2(); cls.foo(); Is there a way to do inheritance in java that java runs both doX and doY when the user calls the function with foo? ...

Tightly integrated private helper class in ASP.NET

Semi-unimportant background: I'm working on a page with two sets of collapsable panels. (using nHibernate) I get category objects with a list of items in them, and for each category generate a left panel and right panel. In both panels, there is a ListBox. Items are pre-populated to the left list box and the user can select and move i...

How should I require different fields on the same object when returned from different methods?

I will have multiple WCF component methods returning a common object. In some cases, fields A,B,C,D will be required to be non-null, but in other cases fields B,F,G,Q may be required to be non-null. I want to indicate to whoever may be creating these methods which fields are required for any particular method. I'd also like to enfor...

How to move from Procedural oriented programming to Object Oriented Programming in PHP

Hi I am working with PHP for last 1.5+ years with procedural oriented programming. I like to move from procedural oriented code to object oriented code. But i am struggling with this. I don't know how to start and where to start. I having basic knowledge of OOP. But i don't have any idea on how to implement that. I hope most of the pe...

What's the difference between public and published class members in Delphi?

Please could someone explain me what's the difference between public and published class members in Delphi? I tried to look at Delphi help and I understand that these members have the same visibility, but I don't understand very well how they differ and when should I use published members instead of public ones. Thanks a lot. ...

Java member object inside class of same type

I am looking at a codebase and I often see something like: public class SomeClass { protected static SomeClass myObject; //... public static SomeClass getObject() { return myOjbect } } I'd like to make sure I understand the purpose behind this. Is it to ensure one instance of the class gets shared even if it is instantiated m...

Kohana - Authenticating Users?

I would like to get started on a simple project using the Kohana 3 framework (looks very promising), but the docs are a bit lacking in my opinion and would like some direction to get my feet wet and get me started. So I have a simple use-case question one that most every application needs. How would you present a login form with a usern...

how to pass a self-reference to constructors in java?

hi there! i have a class A that needs to instantiate a second class B, whose constructor needs a reference to the same object of class A... would look like: public class A { B b; public A() { b = new B(this); } } public class B { A a; public B(A a) { this.a = a; } } well - eclipse keeps com...

Deep inheritance with JavaScript?

Hi, I know that I could do a simple prototypal inheritance in JavaScript like this: var Parent = function() { }; var Child = function() { } Child.prototype = new Parent(); Child.prototype.constructor = Child; However, I'm curious to how one would accomplish deeper inheritances? What about multi-inheritance, is that possible? ...

How to encapsulate private fields that only apply to a few methods

I'm working on modeling a business domain object in a class and am wondering what would be the best way to properly encapsulate private fields that only apply to a few methods. When I started, my code originally looked like this: public class DiscountEngine { public Cart As Cart { get; set;} public Discount As Discount { get; s...