Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following use of the State Pattern, and the lines labelled 1 to 8 :public class ElectronicLock / / ( 1 ) { private

Consider the following use of the State Pattern, and the lines labelled 1 to 8:public class ElectronicLock //(1){ private String entryCode; private LockState state; public ElectronicLock(String entryCode){ this.entryCode = entryCode; } public void setState(LockState state)//(2){ this.state = state; } public String getEntryCode(){ return entryCode(); } public void lock(){ state.lock(this); } public void unlock(String attemptedEntryCode)//(3){ state.unlock(this, attemtedEntryCode); }}public interface LockState //(4){ void lock(ElectronicLock theLock); void unlock(ElectronicLock theLock, String attemptedEntryCode);}public class Locked implements LockState //(5){ @Override public void lock(ElectronicLock theLock)//(6){// Do nothing } @Override void unlock(ElectronicLock theLock, String attemptedEntryCode){ if(theLock.getEntryCode().equals(attemptedEntryCode))//(7){ theLock.setState(new Unlocked()); }}}public class Unlocked implements LockState{ @Override public void lock(ElectronicLock theLock){ theLock.setState(new Locked()); //(8)} @Override void unlock(ElectronicLock theLock, String attemptedEntryCode){// Do nothing }}Match the following code snippets against the text that best describes them (given their context). Note that there is a unique mapping.-(1)public class ElectronicLock {...}-(2)public void setState(LockState state){ this.state = state;}-(3)public void unlock(String attemptedEntryCode){ state.unlock(this, attemtedEntryCode);}-(4)public interface LockState {...}-(5)public class Locked implements LockState {...}-(6)@Overridepublic void lock(ElectronicLock theLock){...}-(7)if(theLock.getEntryCode().equals(attemptedEntryCode)){...}-(8)theLock.setState(new Locked());A. State-dependent method that delegates its logic to the state implementation.B. The class whose state we want to model.C. Implementing a specific state transition.D. One of the state implementations.E. Called by state implementations to transition to different state implementations.F. An implementation of a state-dependent method.G. Represents the abstract concept of an individual state.H. Checking a guard condition.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions