SpecialistOff.NET
/ Вопросы
/ Статьи
/ Фрагменты кода
/ Резюме
/ Метки
/ Помощь
/ Файлы
Назад
Exercises
Метки:
python
- Create an example of the “virtual proxy.”
- Create an example of the “Smart reference” proxy where you keep count of the number of method calls to a particular object.
- Create a program similar to certain DBMS systems that only allow a certain number of connections at any time. To implement this, use a singleton-like system that controls the number of “connection” objects that it creates. When a user is finished with a connection, the system must be informed so that it can check that connection back in to be reused. To guarantee this, provide a proxy object instead of a reference to the actual connection, and design the proxy so that it will cause the connection to be released back to the system.
- Using the State, make a class called UnpredictablePerson which changes the kind of response to its hello( ) method depending on what kind ofMood it’s in. Add an additional kind of Mood called Prozac.
- Create a simple copy-on write implementation.
- Apply TransitionTable.py to the “Washer” problem.
- Create a StateMachine system whereby the current state along with input information determines the next state that the system will be in. To do this, each state must store a reference back to the proxy object (the state controller) so that it can request the state change. Use a HashMap to create a table of states, where the key is a String naming the new state and the value is the new state object. Inside each state subclass override a method nextState( ) that has its own state-transition table. The input to nextState( ) should be a single word that comes from a text file containing one word per line.
- Modify the previous exercise so that the state machine can be configured by creating/modifying a single multi-dimensional array.
- Modify the “mood” exercise from the previous session so that it becomes a state machine using StateMachine.py
- Create an elevator state machine system using StateMachine.py
- Create a heating/air-conditioning system using StateMachine.py
- A generator is an object that produces other objects, just like a factory, except that the generator function doesn’t require any arguments. Create aMouseMoveGenerator which produces correct MouseMove actions as outputs each time the generator function is called (that is, the mouse must move in the proper sequence, thus the possible moves are based on the previous move - it’s another state machine). Add a method to produce an iterator, but this method should take an int argument that specifies the number of moves to produce before hasNext() returns false.
Footnotes
[1] |
No mice were harmed in the creation of this example. |