oop

Must chosen OOP abstraction be as close to life as possible?

I am designing a library for my application, that wraps Windows smartcard subsystem. Physically, there is a smartcard, that is connected to smartcard reader and the reader is connected to PC. There are many types of smartcards (Javacards and .NET cards for example). One idea to design this is as follows: TReaderListBase <- TReaderListJ...

How to describe algorithms when doing Use Cases?

Let's say I'm making an Use Case for a game that has a scoring system. Each action you do in the game will increase/decrease your score in the game. Here is a sketch of my Use Case: 1. ... 2. ... ... 8. The Player makes (some move). 9. The System registers the play and calculates his new score. There is some algorithm behind calculat...

Blocking access to private member variables? Force use of public properties?

Hi, I'm using .NET 2.0 so do not have access to automatic properties. So I must resort to the following way of coding private variables and public properties private string m_hello = null; public string Hello { get{return m_hello;} set{m_hello = value;} } For methods of the containing class of the above private/public memb...

How to signal that a Use Case is over?

Let's say I am making a Use Case about filling a quiz. You have only 5 minutes to fill that quiz. When doing the Use Case for "Filling the Quiz", how should I signal there is a time limit and that after that the Use Case is finished? I simply write it by text or is there anything more formal to use? Sketch of what my Use Case can be: ...

How can I tell the inheriting class to not call its base class' parameter-less constructor?

I was surprised to find out that the parameter-less constructor of my base class is called any time I call any constructor in a derived class. I thought that is what : base() was for, to explicitly call the base constructor if and when I want to. How can I prevent the base constructor from being called when I instantiate a derived cla...

How to make a constructor return a subclassed object.

I just read a book on object-oriented programming patterns. It describes a Factory pattern by which you can make a call to a static factory method of an object and the object will return a new object of expected type, but it will be subclassed appropriately. My question, can this functionality be provided by a constructor for the cla...

Shared data in base class in asp.net

Hi, I have a set of aspx pages which are made of up usercontrols. Each usercontrol inherits from a base class. In that base class I want to put some common data objects (via EF) that I need access to in my user controls. How can I do this efficiently so that each user controls accesses the same class instance or copy of the data? Th...

Is it feasible to create a NullObject for every class? ( with a tool of course )

The NullObjectPattern is intended to be a "safe" ( neutral ) behavior. The idea is create an object that don't do anything ( but doesn't throw NullPointerException either ) For instance the class defined as: class Employee { private String name; private int age; public String getName(){ return name; } public int get...

Better option for strongly-typed containers in javascript

I've just discovered the way to create fake 'classes' in javascript, but I wonder how you can store them and still get easy access to their functions in an IDE. Like this: function Map(){ this.width = 0; this.height = 0; this.layers = new Layers(); } Now I've got a function that loops through an XML and creates multiple Map(...

A query on how to design a bit of class based code for a text adventure game.

I've been learning C# over the summer and now feel like making a small project out of what I've done so far. I've decided on a sort of text based adventure game. The basic structure of the game will involve having a number of sectors(or rooms). Upon entry into a room, a description will be outputted and a number of actions and such you ...

How to JSP display multiple page with one layout (Example index.jsp?page=about display about.jsp)

Hi All! I new in JSP, i have a problem with JSP in php i use $page=$_GET["page"] for display multiple page for one layout it mean i have index , it display layout and when i click on menu go to about us the index url = index.jsp?page=about in PHP when i declare $page above and next step i do Switch($page){ case 1:about includ...

How to "pass" class attribute to a class method?

How can I "pass" eventName to dbSafe() in the following fashion? Is this possible? What would dbSafe() look like? $eventClass->eventName->dbSafe(); I'm guessing dbSafe() would look roughly like this: public function dbSafe() { return mysql_real_escape_string($this); } ...

UML and Algorithms

I am a bit confused about where to describe the algorithm I might use in some part of an application. Let's say I want to create a Use Case that describes how the User inputs a set of values and my application returns the average of those values (of course this is a dead-easy case, but its easier to explain it this way). 1. The User t...

$settings array or Config Class to store project settings?

How should I store settings for project? Which is better - to use a $settings array with all my settings: $settings['max_photos'] = 30; //... or create a singleton Config class with all the settings in it? Class Config { private $max_photos = 30; //... } Any good examples? ...

Why don't oop languages have a 'read only' access modifier?

Every time I write trivial getters (get functions that just return the value of the member) I wonder why don't oop languages simply have a 'read only' access modifier that would allow reading the value of the members of the object but does not allow you to set them just like const things in c++. The private,protected,public access modif...

Why ADTs are good and Inheritance is bad?

Hi fellow stackies. I am a long time OO programmer and a functional programming newbie. From my little exposure algebraic data types only look like a special case of inheritance to me where you only have one level hierarchy and the super class cannot be extended outside the module. So my (potentially dumb) question is: If ADTs are jus...

[PHP PDO] Database abstraction class design question

Hi SO, I am in the process of designing a web app (really it's a hobby, I'm trying to teach myself design, and what better way is there than doing it :). Anyways, I was thinking about how I would deal with my database. I am comfortable with PDO and I was thinking of leveraging PDO in my abstraction class. I am thinking of making a si...

A simple project that uses the basic principles of OOP in Java

Hi everyone. I believe that we will never learn any programming language in depth until we apply all the theories on a real world application. And I kinda suck at the creativity thing :c So I would want to ask for ideas on any simple application that the basic principles in OOP (inheritance, interface, encapsulation, and polymorphism) c...

What is the best way to decalre a global variable in cakePHP

Hi all, I am learning cakePHP 1.26. I got a Controller which got two functions. I was thinking to make $myVariable a global variable so that both functions in the controllers can share it, but I am not sure if this is the best way to declare a global variable in cakePHP: class TestingController extends AppController { var $myVar...

What's the best design pattern for PHP when Class_a only occasionally needs Class_b information?

This project is in PHP, but is fairly language agnostic. I'm building a project that has the following MVC format Main_Class Main_Class_Common --> Class_A --> Class_B --> Class_C --> Class_... --> Class_K Original requests go to the Main_Class which then includes the appropriate main sub class. The majority of a request will...