LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-22-2008, 04:22 PM   #1
manolakis
Member
 
Registered: Nov 2006
Distribution: xubuntu
Posts: 455

Rep: Reputation: 31
Observer/Observable


Hi there,

I actually want to make a Java car park which will accept a number of cars. When a car is entering the park it must decide when to leave. My main problem is how to check when a car must leave. Imagine that the cars will be placed in a vector. Every car will have a time that got in and a time to will get out. Ideally if the time to get out is greater equals than the current runtime it must leave.
I am familiar with the observer/observable design pattern but to be honest I do not really know how to implement it in this case.
I will be really happy if anyone can give me any idea.

Many thanks.
 
Old 11-22-2008, 04:39 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Off the top of my head, I'd suggest:

1. You would have some interface, e.g. "IObservable"
2. Your "cars" would implement "IObservable"
3. Each car would register itself with the "Observer" (the car park), invoking (for example) a "CarPark.add ()" method as it drives in.

'Hope that helps .. PSM
 
Old 11-22-2008, 04:41 PM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977Reputation: 1977
It's pretty hard to read this as anything other than homework as it were... We really can't explain how to design a programming assignment from the initial spec, and homework questions really aren't supposed to be asked here.
 
Old 11-23-2008, 12:10 AM   #4
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 130Reputation: 130
You may want to read up on DelayQueue, it takes most of the work out of your hands.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
example of RMI, Observer & Factory Patterns, TransferObject, Model View Controller manolakis Programming 3 10-27-2007 09:09 AM
Observer added ??? Chikne Slackware 1 11-25-2006 03:09 AM
new observer emarald LinuxQuestions.org Member Intro 1 05-03-2006 03:09 PM
page observer delos Linux - Software 2 01-25-2005 07:35 AM
need some advice on c++ observer design pattern digitized_funk Programming 1 11-13-2003 10:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration