Click here to Skip to main content
16,022,536 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Eg I'm designing one gaming application(Car Race). In that there are n number of users. In the race path, tunnel is there. Inside that tunnel, only one user can enter into it. After that user comes out only, another user can enter into it.

How to design a class for this/
Posted
Updated 26-Jan-10 19:04pm
v2

I can't understand what your parent class describes. Although... if you are warring about the tunnel - maybe it'll be better to close the tunnel gate? :) (for example: the stupid, but most simple way is to have a BOOL variable which will get TRUE value only when the tunnel is empty) :)
 
Share this answer
 
OK, so it would be retarded for a tunnel to be derived from a car. Instead, each car, when it gets to the tunnel, needs to check first if another car is in it. The instance of tunnel will return true until the car in there leaves, and until it does, your code won't let the new car enter the tunnel. which means you'd have a queue of some sort, of cars waiting to enter the tunnel.
 
Share this answer
 
Impossible. Every child class IS an instance of the parent class. Accessing has nothing to do with it, it IS the parent class. You'd have to create some sort of blocking mechanism, by hand, or rethink your design as a whole. Your best bet would be to edit your post and tell us why you want to do this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900