oop

why grouping Design pattern in three parts?

Design pattern can separeted 3 important part: "http://www.dofactory.com/Patterns/Patterns.aspx". why three part? Creational Patterns Structural Patterns Behavioral Patterns How can i separete it into three part? According to what? ...

Elegant ways to print out a bunch of instance attributes in python 2.6?

First some background. I'm parsing a simple file format, and wish to re-use the results in python code later, so I made a very simple class hierarchy and wrote the parser to construct objects from the original records in the text files I'm working from. At the same time I'd like to load the data into a legacy database, the loader files ...

How to extend this design for a generic converter in java?

Here is a small currency converter piece of code: public enum CurrencyType { DOLLAR(1), POUND(1.2), RUPEE(.25); private CurrencyType(double factor) { this.factor = factor; } private double factor; public double getFactor() { return factor; } ...

Object oriented n-tier design. Am I abstracting too much? Or not enough?

Hi guys, I'm building my first enterprise grade solution (at least I'm attempting to make it enterprise grade). I'm trying to follow best practice design patterns but am starting to worry that I might be going too far with abstraction. I'm trying to build my asp.net webforms (in C#) app as an n-tier application. I've created a Data Acc...

C# - Downside to Setting Initial Value in Declaration

Is there any downside to a class like: class Example1 { protected string UserId = (string)Session["user"]; } //versus class Example2 { protected string UserId; public Example2() { UserId = (string)Session["user"]; } } If I always want to set this value is there any downside to Example1? UPDATE: Session["user"] is se...

Dynamically add a field to an object in matlab

Say I have a MATLAB object defined in a class file classdef foo properties bar end end And I create a foo object myfoo = foo(); Now I want to add another field to foo dynamically. What I want is myfoo.newfield = 42; but this will throw an error. I know there is a way to dynamically add a field/property to a MAT...

What's wrong with the architecture of a game object drawing and updating itself?

What are the reasons for and against a game object drawing and updating itself? For example, if you have a game where the player has a position on screen, why not have an all-encompassing class: public class Player { private int x, y, xVelocity, yVelocity; private Sprite s; //... public Player() { // load the sp...

Object Oriented Database - why most of the companies do not use them

Hi, I am pretty new to programming(just finished University). I have been thought in the last 4 years about Object Oriented development and the numerous advantages of this approach. My question is Isn't it easier to use a pure Object Oriented database in development applications? Why Object Oriented database are not as much diffus...

In what circumstances are instance variables declared as '_var' in 'use fields' private?

I'm trying to understand the behavior of the fields pragma, which I find poorly documented, regarding fields prefixed with underscores. This is what the documentation has to say about it: Field names that start with an underscore character are made private to the class and are not visible to subclasses. Inherited fields can be overri...

Creating an instance of a subclass extending an abstract class (Java)

In Java, is there any way to create an instance of any class that extends abstract class A, inside a member method of class A? Classes that extends abstract class A will return their instances with this method, but i don't want to implement same method in all subclasses with a "return this();" kind line. EDIT: Ok sorry for the short exp...

Is this the correct way of speaking to a "Content Manager" Class?

I am creating a silverlight site. I am currently breaking out my ideas into pieces of functionality. One of the idea's I have is the concept of a content manager. This is essentially a UI control with 4 regions. Top, Bottom, Right & Left. I also have a collection of objects that are considered "Menu Items". These are controls that functi...

Help dealing with data dependency between two registration forms

I have a tricky issue here with a registration of both a user and his/her pet. Both the user and the pet are treated as separate entities and both require separate registration forms. However, the user's pet has to be linked to the user via a foreign key in the database. The process is basically that when a new user joins the site, first...

PHP 'instanceof' failing with class constant

I'm working on a framework that I'm trying to type as strongly as I possibly can. (I'm working within PHP and taking some of the ideas that I like from C# and trying to utilize them within this framework.) I'm creating a Collection class that is a collection of domain entities/objects. It's kinda modeled after the List<T> object in .N...

Can I access elements/methods named "button1" "button2" "button3" etc. using "buttoni" inside a for-loop?

I have a bunch of buttons named: button1 button2 button3 etc. Is there a way to basically do this? pseudocode for(int i = 1, i < 15, i++) { button{i}.selected = YES; } This also goes for method calls, etc. I've often thought such a way of calling methods would be very convenient, but I don't think I've ever seen it done when us...

Suggest the way to design several classes

Hi, I'm building simple application on as3. Kind of starship game. What I want to do is to create several different star ships. Each one should have different images (different look), different sets of animation (e.g. when it's flying, burning, damaged), different kind of weapon and also different controllers (e.g. one can be managed by...

JavaScript check if anonymous object has a method

How can I check if an anonymous object that was created as such: var myObj = { prop1: 'no', prop2: function () { return false; } } does indeed have a prop2 defined? prop2 will always be defined as a function, but for some objects it is not required and will not be defined. I tried what was su...

OOP C# Question: Making a Fruit a Pear

Given that I have an instance of Fruit with some properties set, and I want to get those properties into a new Pear instance (because this particular Fruit happens to have the qualities of a pear), what's the best way to achieve this effect? For example, what we can't do is simply cast a Fruit to a Pear, because not all Fruits are Pears...

How to cancel a deeply nested process

I have a class that is a "manager" sort of class. One of it's functions is to signal that the long running process of the class should shut down. It does this by setting a boolean called "IsStopping" in class. public class Foo { bool isStoping void DoWork() { while (!isStopping) { // do work... ...

Using collections/containers/catalogs in Domain Models

Let's say I want to model a cinema. The cinema will have a couple of rooms(for example, 7), where the movies are being played. I wonder how should I design the domain model for this scenario. Should the Cinema class concept concept have a direct association with the 7 rooms? Should the Cinema class concept have an association with a ...

Where to start when doing a Domain Model?

Let's say I've made a list of concepts I'll use to draw my Domain Model. Furthermore, I have a couple of Use Cases from which I did a couple of System Sequence Diagrams. When drawing the Domain Model, I never know where to start from: Designing the model as I believe the system to be. This is, if I am modelling a the human body, I sta...