oop

How exactly do "Objects communicate with each other by passing messages" ?

In several introductory texts on Object-oriented programming, I've come across the above statement. From wikipedia, "In OOP, each object is capable of receiving messages, processing data, and sending messages to other objects and can be viewed as an independent 'machine' with a distinct role or responsibility." What exactly does the s...

OOP: self-drawing shapes and barking dogs

Greetings. Most of the books on OOP I've read used either a Shape class with a Shape.draw() member function or a Dog class with a Dog.talk() member function, or something similar, to demonstrate the concept of polymorphism. Now, this has been a source of confusion for me, which has nothing to do with polymorphism. While... class Dog : ...

Is it possible to have an instance of a class as a data member of another class?

I have a Board class where the constructor takes in the dimensions of the board as the parameter. I also have a Puzzle class that holds pieces and I want it to have a Board as a data member. I want it like this so that when I create an instance of Puzzle, I will have my instance of board created as well so I dont have to make seperate ...

Help me with a solution for what could be solutioned by virtual static fields... in FPC

Hi I'm doing an event manager in Freepascal Each event is an object type TEvent (=object), each kind of event must derive from this class. Events are differentiated by an integer identificator, assigned dynamically. The problem is that i want to retrieve the event id of an instance, and i can't do it well. All instances of a class(obj...

Replacement for C style struct in OOP

Hey all, I am a student with a mainly electronics background getting into programing. The more I get into it, the more I realize how bad I am at it. I am trying to get better at OO design. One thing I have been reading about is the use of Getters and Setters. http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html?page=1 ...

Prep for Beginning CSIS: Java Programming

I am going to begin my Computer Science & Information Systems degree in April. My first class is an introduction to Java programming. Lately I have had an interest in Objective-C, but slowly declined due to lack of persistence and comprehension difficulties, (mostly some OOP). Obviously I would like to do well in my classes, so I am ask...

ORM with automatic client-server data syncronization. Are there any ready to use solutions?

Consider the client application that should store its data on remote server. We do not want it to access this data "on-fly", but rather want it to have a copy of this data in local database. So we do not need connection with remote server to use application. Eventually we want to sync local database with remote server. The good example o...

c++ development on Mac

I have till now mainly concentrated on web programming thus far and now want to enter application programming space. I use a mac, and wanted to know what sort of compilers, IDEs etc people generally use for c++ dev. extremely n00b One more thing immensely bothering me was the fact that c++ compilers generally output .exe which cant be ...

Adding virtual functions without modifying the original classes

Let's say we already have a hierarchy of classes, e.g. class Shape { virtual void get_area() = 0; }; class Square : Shape { ... }; class Circle : Shape { ... }; etc. Now let's say that I want to (effectively) add a virtual draw() = 0 method to Shape with appropriate definitions in each sub-class. However, let's say I want to do this w...

Representing files and lines in a file in model view?

Hi, I am trying to come up with a model design to solve the follwoing problem: I have files (plain text and xml) which I want to be able to represrnt them in a view in ASP.NET, also, I would need to detect certain words in lines and keep track of them. So, we can imagine I have the following CFile: List<Message> CertainMessages M...

How to create a "genuinely extensible" class

I have read a lot of articles on developing classes (I am using php), with the tag lines : 'scalable, robust, maintainable and extensible'. But as a beginner, I have been creating classes that are, in my words, "just abstracted". Meaning I just separated a bunch or repetitive codes and put them in a class and provide methods for access...

How to model a duration in an object oriented way?

I'm dealing with different APIs that use Integers to model duration. Only they can't seem to agree on the units. Sometimes it's seconds and sometimes it's milliseconds. So far the best way to avoid errors I've been able to find, is to use Hungarian notation: durationInMillis, durationInSeconds and so on. It makes me wonder if there's ...

Why cant i set $_SERVER['DOCUMENT_ROOT'] as Attribute?

Why cant i set $_SERVER['DOCUMENT_ROOT'] as attribute? see example code class foo { private $path = $_SERVER['DOCUMENT_ROOT']; // generates error private $blah; public function __construct() { //code } public function setBla($bla) { $this->blah = $bla; } } ...

Delphi Enterprise: how can I apply the Visitor Pattern without circular references?

With Delphi 2009 Enterprise I created code for the GoF Visitor Pattern in the model view, and separated the code in two units: one for the domain model classes, one for the visitor (because I might need other units for different visitor implementations, everything in one unit? 'Big ball of mud' ahead!). unit VisitorUnit; interface use...

Link between BO and GUI is broken. What to do?

I have some points (car stops) to represent on a time graph. These points are linked between them by lines. Points + Lines represent a Graph (that is a car schedule). The Graph can be modified by moving CarStops in time with the mouse. I decided to implement Points and Lines as controls (thought that will be easier to move them on the p...

Running a loop (such as one for a mock webserver) within a thread

I'm trying to run a mock webserver within a thread within a class. I've tried passing the class' @server property to the thread block but as soon as I try to do server.accept the thread stops. Is there some way to make this work? I want to basically be able to run a webserver off of this script while still taking user input via stdin.get...

One Vs Multiple Objects - Java or any other OOP

Let's say I need to design a system for a collection of books. And let's assume I have millions of books and for simplicity we don't need to add or remove books from the system. I can create a Book class and initiate an array in the size of the collection: Book book = new Book[number of books]; In this case, Book would include fields...

Copy and extend global objects in javascript

Hi, is there a way to copy a global object (Array,String...) and then extend the prototype of the copy without affecting the original one? I've tried with this: var copy=Array; copy.prototype.test=2; But if i check Array.prototype.test it's 2 because the Array object is passed by reference. I want to know if there's a way to make the ...

Would it be fair to say learning Java would make me a better PHP OOP Developer?

Would it be fair to say learning Java would make me a better PHP OOP Developer? I've been looking into Java so I can understand OOP better. Should I continue learning Java to better understand OOP or would I be better off sticking with PHP OPP. I've just learnt about interfaces and abstract classes, will I really use these in PHP? Any ad...

How do you manage an object graph in Haskell?

I'm trying to re-learn systems analysis. I've got a lot of object-oriented thinking for which I'm not able to find equivalents in Haskell, yet. A fictional system consists of Ambulance Stations, Ambulances and Crew. (It's getting object-y already.) All this state can be wrapped up in a big SystemState type. SystemState [Stations] [A...