oop

Class design question (Disposable and singleton behavior)

The Repository class has singleton behavior and the _db implements the disposable pattern. As excepted the _db object gets disposed after the first call and because of the singleton behavior any other call of _db will crash. [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)] public class Repository : IRepository { ...

Magento - How do I create a shopping cart price rule automatically?

I'd like to create a shopping cart price rule that gives a user 10% off their order when and if they complete a process on my Magento site. There's a method here that inserts the rule directly to the database. That's a bit invasive for my tastes. How would I go about this using Magento methods? ...

JavaScript prototype(ing) question

Trying to grasp Prototyping in Javascript. Trying to create my own namespace to extend the String object in JavaScript. Here is what I have so far (a snippet): var ns { alert: function() { alert (this); } } String.prototype.$ns = ns; As you can see, I am trying to place what will be a series of functions into the ns namespace. So...

Is there a case for parameterising using Abstract classes rather than Interfaces?

I'm currently developing a component based API that is heavily stateful. The top level components implement around a dozen interfaces each. The stock top-level components therefore sit ontop of a stack of Abstract implementations which in turn contain multiple mixin implementations and implement multiple mixin interfaces. So far, so go...

how to handle exceptions/errors in php?

when using 3rd part libraries they tend to throw exceptions to the browser and hence kill the script. eg. if im using doctrine and insert a duplicate record to the database it will throw an exception. i wonder, what is best practice for handling these exceptions. should i always do a try...catch? but doesn't that mean that i will hav...

should I ever put a major version number into a C#/Java namespace?

I am designing a set of 'service' layer objects (data objects and interface definitions) for a WCF web service (that will be consumed by third party clients i.e. not in-house, so outside my direct control). I know that I am not going to get the interface definition exactly right - and am wanting to prepare for the time when I know that ...

how can we call one class's method through another class's object in php

I want to know that is there any method in PHP by which i can call one class's method from another class object. let me clear here is one class class A() { public function showData(){ //here is method of class A } } // here is another class class B(){ public function getData(){ //some method in ...

What are the benefits of prototypal inheritance over classical?

So I finally stopped dragging my feet all these years and decided to learn JavaScript "properly". One of the most head-scratching elements of the languages design is it's implementation of inheritance. Having experience in Ruby, I was really happy to see closures and dynamic typing; but for the life of me can't figure out what benefits...

Why is an object model necessary in project?

Why is an object model necessary in project? ...

Simple OOP-related question.

This question came to my mind quite a few times. Let my explain my question through an example. Say I've got two classes: 1- Grid. 2- Cell. Now the location of the cell 'should' be stored in the grid class, not in the cell class itself. Say that the cell wanted to get its location through a method in the grid. How can it do that? Kee...

PHP: OOP and methods

Hello I`ve been wondering how to implement methods in a class. Could someone explain me what means if one does OOP in procedural style? Here is an example: class Fld extends Model { private $file; private $properties = array(); public function init($file) { $this->file = $file; $this->parseFile(); } private funct...

Overwrite method at runtime in python

I have method that run many times. I dont want to nest ifs inside but rather want to overwrite method and then run it. I know that i can overwrite class method by simple assigment, but overwriten method doesn't see private members: class X: def __init__(self, a): self.a = a self.__b = a def m(self): prin...

A self-creator: What pattern is this? php

I have several classes that are basically interfaces to database rows. Since the class assumes that a row already exists ( __construct expects a field value ), there is a public static function that allows creation of the row and returns an instance of the class. Here's a pseudo-code ( so there are mistakes and missing improvements in ...

JavaScript String Library - Hitting a Minor Roadblock

Ok - am trying to create a string library that contains a handful of useful things missing from JavaScript. Here is what I have so far: function $__STRING__$(in_string) { this.s = in_string; } $__STRING__$.prototype = { uppercase: function(){this.s = this.s.toUpperCase(); return this;}, lowercase: function(){this.s = t...

PHP: How to access array values returned by a static function?

I am running following code, getAccount() is a static function, $ac_info = AccountClass::getAccount($ac_code); print_r($ac_info); and getting following output AccountClass Object ( [account_code] => [email protected] [username] => XYZ [email] => [first_name] => [last_name] => [company_name] => [id] => [email protected] [balance_in_cents]...

C# OOP File Structure?

Hey SO, I just started programming with objects recently and am trying to learn good habits early on. The way I plan to structure my application is to have two files: 1: Program.cs - This file will contain the main logic for the application 2: Class.cs - This file will contain all of the class definitions Pretty simple. What I'm w...

Not very objective - please help

I am having trouble understanding the meaning and more importantly the concept of an object as it relates to jQuery. I understand the basics that its a collection of data that comes in two forms, properties and methods but I kind of get lost on how it works beyond that. Can anyone point me to some good tutorials that maybe helped you und...

What's the behavior when you re-specify an interface already implemented by a base class

Given the following code: public interface IExample { ... } public abstract class BaseExample: IExample { ... } public class ExampleA : BaseExample { ... } public class ExampleB : BaseExample, IExample { ... } Are there any benefits or drawbacks in writing code like ExampleB? My guess is that re-specifying IExample in the derived cl...

Alternatives to static methods on interfaces for enforcing consistency

In Java, I'd like to be able to define marker interfaces, that forced implementations to provide static methods. For example, for simple text-serialization/deserialization I'd like to be able to define an interface that looked something like this: public interface TextTransformable<T>{ public static T fromText(String text); public...

OOP design issue: Polymorphism

I'm trying to solve a design issue using inheritance based polymorphism and dynamic binding. I have an abstract superclass and two subclasses. The superclass contains common behaviour. SubClassA and SubClassB define some different methods: SubClassA defines a method performTransform(), but SubClassB does not. So the following example 1...