oop

constructor methods in interfaces

Are constructor methods in interfaces bad? ...

_Underscores in Function Names

In a lot of languages with simple OO capability (PHP 4), or misunderstood OO capabilities (Javascript, C using function pointers, etc.), you'll end up with a function naming convention that uses leading underscores to to indicate privilege level. //ex. function _myPrivateFunction(){ } While individual teams are always going to come...

Python Module/Class Variable Bleeding

Okay, it took me a little while to narrow down this problem, but it appears python is doing this one purpose. Can someone explain why this is happening and what I can do to fix this? File: library/testModule.py class testClass: myvars = dict() def __getattr__(self, k): if self.myvars.has_key(k): return sel...

In Python, can you call an instance method of class A, but pass in an instance of class B?

In the interest of reusing some existing code that was defined as an instance method of a different class, I was tying to do something like the following: class Foo(object): def __init__(self): self.name = "Foo" def hello(self): print "Hello, I am " + self.name + "." class Bar(object): def __init__(self): self.name =...

Calling Parent Class From Sub Class PHP

Hello There http://stackoverflow.com/questions/742097/this-a-b-c-d-calling-methods-from-a-superclass-in-php Ive asked a question on this link I ve problem with this tecnique I am able to call the sub classes from a class like this $chesterx->db->query(); I wanna do get another class from sub class for example i want to query exe...

MVP and multiple User Controls

I’m trying to use the MVP pattern and I’m running into a design problem. I’m developing an application that will have several UserControls. The UserControls themselves have nothing to do with one another and only represent a subset of the actual model. From what I’ve read, people tend to say you should use one Presenter per View. Thi...

Abstract classes vs interfaces to represent a family

Abstract classes are described as being useful for a family of objects (e.g. could be used for animals which are mammals). However, what difference is there between using an interface or abstract class for representing a family of related objects? My process is to use an abstract class when I want to define common functionality but with...

How to decide if a method will be private, protected, internal or public? (C#)

I am designing a class where some methods won't cause any harm if they are exposed as public. But they can be private as well, since they will be used only from the same class in my project. Making them public has the following advantages: Unit Testable without the need of accessors. Flexibility. Making them private has the followin...

Object oriented analysis and real life OOP differences

I usually try to do TDD with not much analysis (no diagrams) before start coding. Usually I find myself spliting a class into other classes to separate concerns. I wonder if a deeper analysis would prevent that. I think that much of OO analysis can't predict some of those cases. What do you think? ...

C# class both extends an abstract class and implements an interface

What if I have a class that both extends an abstract class and implements an interface, for example: class Example : AbstractExample, ExampleInterface { // class content here } How can I initialize this class so I can access methods from both the interface and the abstract class? When I do: AbstractExample example = new Example(...

Why builtin functions instead of root class methods?

(I'm sure this is a FAQ, but also hard to google) Why does Python use abs(x) instead of x.abs? As far as I see everything abs() does besides calling x.__abs__ could just as well be implemented in object.abs() Is it historical, because there hasn't always been a root class? ...

Global variables as aliases for singletons?

Hi! I'm developing a Cocoa (Touch) app and there's certain data (like own device information and a list of locations) that I have to persist between different views and controllers. I thought of storing it as instance variables in my App Delegate, but addressing the delegate is quite cumbersome (no joy typing [[[UIApplication sharedAp...

Terminology - parts of a composite relationship

Assume I have a composite relationship, say a Customer having a collection of Orders (and assuming an Order cannot exist without an "owning" Customer.) So, I'm not talking about aggregation. What terms are used to describe the roles in this relationship? I might say the Customer is the "owner" of an Order and maybe the Order is "owned"...

using abstract keyword in interface

I know the difference between "public interface" and "public abstract interface", but when applied on methods are there differences? public interface IPluggableUi { abstract public JComponent getPanel(); abstract public void initUi(); } or public interface IPluggableUi { public JComponent getPanel(); public void initU...

How to design an object which can be one of two types ?

I'm reading a HTTP POST and the body of the HTTP request can be either JSON or XML. Now I've delegated the reading to a special utility class. interface HttpUtils { BodyWrapper parseBody( HttpServletRequest req ); } interface BodyWrapper { boolean isXML(); // 1 boolean isJSON(); // 2 String body(); // 3 } I hate ...

extending a Singleton class?

Is there a way to make like a template singleton class so that when you extend it, the extended class is also a singleton class, so I can quickly make a new singleton class just my extending the template singleton class? I am using ActionScript 3.0 if it matters. Thanks. ...

Is this a good use of the Singleton pattern?

I make a lot of "design your own ____" applications. What I do is I make a singleton class to hold all the customizations the user has chosen. For example: When you select you want something green, it updates a getter/setter in the singleton to be green. Then when the application needs to know what color was selected it gets the info fro...

What is this pattern called (helps avoid type casting)?

Found myself trying to find a link to an official definition of this design pattern which I believe I saw in Go4 but can't seem to find it anywhere. class Processor{ ProcessParameter(AbstractParameter x){ x.Process(this); } ProcessParameter(ParameterA x){ ... A-specific logic... } ProcessParameter(Paramet...

Model shared between two objects

I have three classes interacting in an interesting way. One is a model class, and it has to be accessed by both of the other classes, so a single instance of it is kept as a member of each. Both of these classes interact with the model in different ways. There are a couple of instances where the model object has to be completely throw...

Word for "settings"

Context (example): In windows explorer in "Folder Options" there is a section called "Advanced Settings" where "settings" is a set of pairs (name : value), e.g. "Do not cache thumbnails" : On "Hidden files and folders" : "Do not show hidden files and folders" What is a correct name for each of those pairs? Is it "setting"? Questi...