oop

How would you code a washing machine?

Imagine I have a class that represents a simple washing machine. It can perform following operations in the following order: turn on -> wash -> centrifuge -> turn off. I see two basic alternatives: A) I can have a class WashingMachine with methods turnOn(), wash(int minutes), centrifuge(int revs), turnOff(). The problem with this is th...

dynamic behavior of factory class

I have a factory class that serves out a bunch of properties. Now, the properties might come either from a database or from a properties file. This is what I've come up with. public class Factory { private static final INSTANCE = new Factory(source); private Factory(DbSource source) { // read from db, save properties...

How would I associate a "Note" class to 4+ classes without creating lookup table for each association.

I'm creating a project tasklist application. I have project, section, task, issue classes, and would like to use one class to be able to add simple notes to any object instance of those classes. The task, issue tables both use a standard identity field as a primary key. The section table has a two field primary key. The project table ...

Aspect-Oriented Programming in OOP world - breaking rules ?

Hi 2 all! When I worked on asp.net mvc web site project, I investigated different approaches for validation. Some of them were DataAnotation validation and Validation Block. They use attributes for setting up rules for validation. Like this: [Required] public string Name {get;set;} I was confused how this approach combines with SRP (...

What is the best way to store site configuration data?

I have a question about storing site configuration data. We have a platform for web applications. The idea is that different clients can have their data hosted and displayed on their own site which sits on top of this platform. Each site has a configuration which determines which panels relevant to the client appear on which pages. The...

Method hiding with interfaces

interface IFoo { int MyReadOnlyVar { get; } } class Foo : IFoo { int MyReadOnlyVar { get; set; } } public IFoo GetFoo() { return new Foo { MyReadOnlyVar = 1 }; } Is the above an acceptable way of implementing a readonly/immutable object? The immutability of IFoo can be broken with a temporary cast to Foo. In general (...

OOP, Interface Design and Encapsulation

C# project, but it could be applied to any OO languages. 3 interfaces interacting: public interface IPublicData {} public /* internal */ interface IInternalDataProducer { string GetData(); } public interface IPublicWorker { IPublicData DoWork(); IInternalDataProducer GetInternalProducer(); } public class Engine { Engine(I...

Multi-level inheritance with Implements on properties in VB.NET vs C#

Let's say I have 2 interfaces defined like so: public interface ISkuItem { public string SKU { get; set; } } public interface ICartItem : ISkuItem { public int Quantity { get; set; } public bool IsDiscountable { get; set; } } When I go to implement the interface in C#, VS produces the following templated code: public cl...

Multi-level interface inheritance with .NET and COM Interop

This question is a follow-up to my last question with a reference to COM Interop. Let's say I have the following 2 interfaces and implementing classes: public interface ISkuItem { public string SKU { get; set; } } public interface ICartItem : ISkuItem { public int Quantity { get; set; } public bool IsDiscountable { ...

Object Oriented ANSI C?

Possible Duplicate: Can you write object oriented code in C? Hello, I'm wondering if it's possible to use strict ANSI C as a object oriented language. And if it's possible, how do I make a class in ANSI C. Allthough the language isn't designed for OO, I'm really eager to try this. Any examples, links etc. are appreciated. T...

Should private functions modify field variable, or use a return value?

I'm often running into the same trail of thought when I'm creating private methods, which application is to modify (usually initialize) an existing variable in scope of the class. I can't decide which of the following two methods I prefer. Lets say we have a class Test with a field variable x. Let it be an integer. How do you usually m...

Is it good practice to have DTO objects deepy integrated in code?

I'm building a fairly large application that makes use of the DAO/DTO design pattern to obtain data from a database. In the application a particular DTO has become the "core data structure" in that it's referenced all throughout the project. I'm wondering if it is a good practice to have this DTO so deeply integrated throughout the proje...

Using object variables inside other classes

I have an object whose functions I would like to call from with in another class for example class smo { int spoon = 10; smo() { } int get_spoon() { return spoon; } } class boat { boat() { } print_smo(Object test) { test.get_spoon(); } } it tells me that the function get.spoo...

PHP OOP Problem

Hi, I have a following class in php - class BaseDatabase { private $host; private $user; private $password; private $database; private $connection; private $IDatabase; // This variable will point to an instance of a class // which implements the "IDatabase" interface privat...

What is the purpose of the intial function in a PHP class which has the same name as the class?

So I am getting started with OO PHP, and after reviewing a variety of classes which I have downloaded from the internet, I have noticed that some - but not all of these classes have an intial function with the same name e.g. class MyClass{ function MyClass{ //function contents in here } function otherfunction{ //more stuff here } ...

Accessing class member variables inside an event handler in Javascript

I have a quick question regarding the proper way to access Javascript class member variables from inside of an event handler that class uses. For example: function Map() { this.x = 0; this.y = 0; $("body").mousemove( function(event) { this.x = event.pageX; // Is not able to access Map's member variable "x" ...

Derived classes and singleton

Hello all, If I have two classes "A" and "B", is it OK to derive B from A and then make B a Singleton?. Thanks for your help. ...

An Alternative OO Language to C++ with Similar Powers ?

Greetings All, I'm looking for an OO language that support pointers and (if possible) GC. Though it would be nice NOT to enforce GC and allow for override/customize it. I'm open to both VM and binary executable languages. I'm looking for a consistent and proactively developed/supported OO language to do development with. Maybe I am no...

Accessing DB via function vs object, difference?

Possible Duplicate: PHP PDO vs normal mysql_connect So in my application, I accessed the database via a function named db_connect();. Quite simply, it fed the requisite login information and opened a database connection via mysql_connect and mysql_select_db. Now that I'm working, I have found that the lead programmer uses PDO...

What is the term for exposing members (of members, of...) to provide their functionality in a class using composition?

UPDATE: My original question wasn't quite clear. I'm looking for the name of the principle that code like the example below violates. (I've updated the code example to better resemble the scenario I'm talking about. The original code example I included can be found at the bottom. This was a poorly chosen example because it illustrated a...