oop

Limit instances creation of a class?

I am using C#. I have created a class which can be included in any c#.net project (desktop or web based), but I want that only 10 objects will be created in that application of my class. If object instances created more than 10 then it should give an error or simple will not work. There can be two situations, I'll included myclass.cs...

Sharing DB connections across objects using class methods in ruby?

Hello, I am writing a ruby script to be used as Postfix SMTP access policy delegation. The script needs to access a Tokyo Tyrant database. I am using EventMachine to take care of network connections. EventMachine needs a EventMachine::Connection class that is instantiated by EventMachine‘s processing loop whenever a new connection is cr...

Controlling partial views re:Contact forms

Ok, so here's where I'm at. I've been studying MVC/OOP, trying to roll my own as an exercise. I think I've finally grepped the purpose of each letter in the MVC acronym - my question here pertains to a design decision. I've set up an FC of sorts - it takes parameters from the $_GET array and loads the appropriate sub-template into a ma...

Thread Safe Class Library Design

I'm working on a class library and have opted for a route with my design to make implementation and thread safety slightly easier, however I'm wondering if there might be a better approach. A brief background is that I have a multi-threaded heuristic algorithm within a class library, that once set-up with a scenario should attempt to so...

Importance of OOP concepts? Are they really used to full extent???

Hi all, The question seems pretty simple, and so is the answer. I am a developer who recently started working. So far I had taken few bachelor and master level courses on OOP. And yet I am not comfirtable and confident with OOP concepts. Recently, I was searching for employment opportunities and I found that many employers were keen to ...

Object Graphs and Inheritance

I vaguely understand the concept of an object graph. Does it only apply to in memory objects built via composition; or is inheritance a structual attribute of the graph as well? ...

When do I use static variables/functions in php?

I am refreshing myself on OOP with PHP and I saw an example of setting functions and/or variables as static. When and why would I set a variable/function to static? I've done other languages and don't really recall ever using static, I never found a real purpose to it. I know what it does but why not just use a variable instead? ...

Writing an app to interact with SQL 2008 without managed code

I want to write a winPE(vista) application that connects to a DB and just writes a row in a table saying it booted winPE. Here is my problem. I only ever do .NET. I'm pretty familiar with OO concepts so I'm finally taking the plunge to unmanaged code. I assume I have to use visual studio's unmanaged c++ project type, but I don't know wh...

Is it a good idea to use super() in Python?

Or should I just explicitly reference the superclasses whose methods I want to call? It seems brittle to repeat the names of super classes when referencing their constructors, but this page http://fuhm.net/super-harmful/ makes some good arguments against using super(). ...

Achieving State like pattern without having +3 entities? C#

Here is the design problem in pseudo example: It is ASP.NET User control (UC) which uses the "Food" object as data source and this object has property FoodType - "Veg" || "Nonveg". The user control changes UI display depending upon FoodType property. In code-behind class of User Control, some methods have same if/then/else condition: ...

How can I maintain control of the this keyword when extending prototypes in jQuery?

I'm implementing a class-like structure in jQuery, but I'm having some trouble when I try to call some of my functions. This is how the structure is setup: MyClass = function(name) { this.init(name); } $.extend(MyClass.prototype, { init: function(theName) { this.myFunction(); // works $('.myclass').each(function(){ ...

Multiple Inheritance in java.

Java is not allowing inheritance from multiple classes (still it allows inheritance from multiple interfaces.), I know it is very much inline with classic diamond problem. But my questions is why java is not allowing multiple inheritance like C++ when there is no ambiguity (and hence no chances of diamond problem) while inheriting from m...

Should this code have been a Base class instead of an Interface?

Interface vs. Base class is still a fairly gray area to me. I'm reading a book on ASP.NET 3.5 Enterprise Development and the author states that all tables will have the following fields: InsertDate InsertENTUserAccountId UpdateDate UpdateENTUserAccountId Version If this were me coding the above requirement, I would create a base busi...

Is this a good way to do JS OOP?

I wanted to ask about the pros cons of my the following OOP style. I write my JS classes in the following manner. var MyClass = function() { // private vars var self = this, _foo = 1, _bar = "test"; // public vars this.cool = true; // private methods var initialize = function(a, b) { // ...

If I have two instance of a class and I use $this to reference one of the instance without specifying which, what will $this take?

PHP scripts register.php: $compareUser = new User(); $user = new User; verify.php (executes with a link from register.php, passes two variables to User.php) User.php setActive($token, $uid){ $this->username = /???? } *assuming that User has a username property, which instance of the User class will $this take? $compareUser o...

Is global constants an anti-pattern?

I've always thought having a class just for the sake of holding constants is a bad design. But recently, I've tried googling for it and found only that having an interface as a constants is bad an anti-pattern - no mention of using a class of constants. I'm of the opinion that since a class of constants is really not much different from...

Interface naming for adjectives

OK, so it's easy to name an interface (or class for that matter) if you can easily think of a noun: User, Window, Database, Stream, etc. What about an adjective or adjective concept? e.g. something that has a timestamp (HasTimestamp, Timestamped, Timestampable...?) or something that is tracked or watched (Trackable, IsTracked, Watchable...

Confusion in line about the difference between instance and object in context of Java

Hi, Could anyone please what the following is saying about instance and object: If class is the general representation of an object, an instance is its concrete representation. I know concrete means non-abstract. So what's actually general representation and concrete representation? ...

How do I maintain a $this reference across two classes in different scripts?

ok, that's a bit odd but here's the situation: I am working in an MVC context I have a User class used as a library(User.php) ANd then I have a controller class that handles input from the user(controller.php) Here's how it goes: user registers registerhandler() is called in controller registerhandler() calls register() method in U...

Terminology: What's the difference between a class and a component?

Within the OO paradigm, we choose to use classes because they help us to break the system down, and provide nice side benefits such as encapsulation, separation of responsibilities, inheritance, modularity, etc. If we look at a software system at the component level, can we simply treat components in the same conceptual way, i.e. a comp...