oop

Suggestions for how to clean up this API

For a fun project I'm trying to implement the BitTorrent spec, and right now I'm working on the BEncoding portion of it. The encoding basically can encode from int/string/dictionary -> string for transmission. I've got all of the different encodings written/tested/working as overloaded Encode(...) methods and I've got the individual de...

How to validate classes in a hierarchy in a generic type-safe way?

Hey guys, I'm stuck with what seemed to be a very simple task at the very beginning. I have a class hierarchy each class in which can define its own validation rules. Defining validation rules should be as simple as possible. Here is what is almost what is needed: class HierarchyBase { private List<Func<object, bool>> rules = new ...

Is there any difference between UML Use Case "extends" and inherance?

Or the "extends" is a use case inheriting another? --update Just a clarification, I've read books and made a lot of diagrams. But I just can't see any difference between extends on UML and on inherance. As Bill said, UML extends indicates optional behavior, but in inherance either you get new behavior you can or not use. So, what's the...

Class hierarchy in C#: how to do it correctly? ('friend' keyword wanted)

I have a class: public class MyClass { private List<string> folderList; // .... a lot of useful public methods here..... } Everything is fine. The list of folders is encapsulated, the class is accessible through public methods. OK. Now I need an "options" form that allows a user to choose folders for MyClass. There is a catc...

Help for designing a chess game

I am a C++ programmer trying to learn designing, as a start I am trying to get a hang of designing by giving myself a task to make a OO design for a game of chess.This is not a homework q just trying to develop some skills. Here is the summary of what i have in my mind till now: A "Piece" class which will hold the current position of the...

Group functions of similar functionality

Sometimes I come across this problem where you have a set of functions that obviously belong to the same group. Those functions are needed at several places, and often together. To give a specific example: consider the filemtime, fileatime and filectime functions. They all provide a similar functionality. If you are building something l...

oo javascript with properties from server, methods from cache, best practice?

I'm converting procedural JS to OO and would appreciate any help. In a nutshell, what I have is a html-page containing: <script type="text/javascript"> var serverTime='11:32:20'; //time generated by server (php) </script> <script scr="myProcFuncs.js" type="text/javascript"> /* which is containing procedural functions such as fun...

How does an object reference itself in Javascript?

I was experimenting with inheritance in javascript, and wrote those two functions: Object.prototype.inherits=function(obj){this.prototype=new obj;} Object.prototype.pass=function(obj){obj.prototype=new this;} This code works very well: Dog.inherits(Animal); But the following fails: Animal.pass(Dog); As I understand it, my pass f...

Steps to follow when trying to OO design an problem statement

What are the steps that you follow when approaching a problem statement, which needs to be converted in to a OO design. I do know the approach might be subjective depending on the problem and varying for each but I am sure there must be some basic generic steps that each good designer will follow while breaking down a problem statement i...

object oriented programming basics (python)

Hi Level: Beginner In the following code my 'samePoint' function returns False where i am expecting True. Any hints? import math class cPoint: def __init__(self,x,y): self.x = x self.y = y self.radius = math.sqrt(self.x*self.x + self.y*self.y) self.angle = math.atan2(self.y,self.x) def cartesia...

Overuse of mixin is evil and what are the alternative solutions?

Sometimes using mixin with multiple inheritance can help us improve reusability of our code. For example, the following design class FollowableMixin(object): def get_followers(self): ... ... class User(FollowableMixin): ... may be better reused than simply adding get_followers to User: class User(object): de...

When programming iOS ViewControllers should you call parent class methods before or after your own code?

A new iOS ViewControllers created from a template contains several "boilerplate" methods that call their parent class methods. -(void) viewDidLoad { [super viewDidLoad]; } - (void) viewDidUnload { [super viewDidUnload]; } - (void) dealloc { [super dealloc]; } When modify these classes, should I put my own cod...

the best OO framework in Coldfusion9

Hi I am new to OO frameworks in general such as MVC, Coldspring,etc but I have read about their benefits - could someone point tell me which one is the best - may be with standard to other programming language. Many thanks ...

object oriented programming basics: inheritance & shadowing (Python)

Hi Level: Beginner I'm doing my first steps in Object Oriented programming. The code is aimed at showing how methods are passed up the chain. So when i call UG.say(person, 'but i like') the method say is instructed to call class MITPerson. Given that MITPerson does not contain a say method it will pass it up to class Person. I think t...

Javascript can implement OOP but Ruby can't implement functional programming?

Im new to "real" Javascript:ing and I know understand more of functional programming. It seems that in Javascript you get the best from both worlds: functional and object oriented programming. But in Ruby, you don't have first class functions (function as a datatype). Does this mean that Javascript embraces the best of the both worlds...

static properties and instances

Hi, What will happen if I create a class with a static property and create two instances of it? Will the static property will be shared between both instances and not be duplicated? Thanks, Yossi ...

Can a Discriminator Column be part of the Primary Key in Doctrine2?

I'm using Single Table Inheritance in Doctrine2 to store OAuth credentials for multiple services. I'd like to use the service's id as the primary key; however, that's not unique across all services. I've setup the database to use the discriminator column and the service's id as the primary key, but I can't find a way to make Doctrine u...

Using function pointer member variables within an Objective-C Class

Hi, (New to Objective-C, but well versed in C/C++). Presently I have an Objective-C class and a number of its member variables will be function pointers. These function pointers will only be modified by the class itself, but may be used by other classes. I'm not sure how to set up access to said function pointers. The solution I cur...

How does virtual method invocation work in C++?

How does Virtual Method Invocation work in C++? ...

Magento - How do I use a shopping cart price rule to display a cms block?

I would like to use a shopping cart price rule to display a cross sell message rather than setting a discount. For instance, if a certain item is in the cart, display the promotional message in the cross sell area. Specifically, we have jacket and pants that can be purchased separately. But when purchased together, the customer can sa...