2017-05-29 21:53:05 +03:00
|
|
|
/**
|
|
|
|
* The MIT License
|
|
|
|
* Copyright (c) 2014 Ilkka Seppälä
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2017-05-23 01:38:02 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2017-04-28 19:35:19 +02:00
|
|
|
/**
|
|
|
|
* Created by Alexis on 28-Apr-17.
|
2017-05-03 17:50:35 +02:00
|
|
|
* With Marker interface idea is to make empty interface and extend it.
|
|
|
|
* Basically it is just to identify the special objects from normal objects.
|
|
|
|
* Like in case of serialization , objects that need to be serialized must implement serializable interface
|
|
|
|
* (it is empty interface) and down the line writeObject() method must be checking
|
|
|
|
* if it is a instance of serializable or not.
|
|
|
|
* <p>
|
|
|
|
* Marker interface vs annotation
|
|
|
|
* Marker interfaces and marker annotations both have their uses,
|
|
|
|
* neither of them is obsolete or always better then the other one.
|
|
|
|
* If you want to define a type that does not have any new methods associated with it,
|
|
|
|
* a marker interface is the way to go.
|
|
|
|
* If you want to mark program elements other than classes and interfaces,
|
|
|
|
* to allow for the possibility of adding more information to the marker in the future,
|
|
|
|
* or to fit the marker into a framework that already makes heavy use of annotation types,
|
|
|
|
* then a marker annotation is the correct choice
|
2017-04-28 19:35:19 +02:00
|
|
|
*/
|
|
|
|
public class App {
|
2017-05-03 17:50:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Program entry point
|
|
|
|
*
|
|
|
|
* @param args command line args
|
|
|
|
*/
|
2017-04-29 16:35:57 +02:00
|
|
|
public static void main(String[] args) {
|
2017-05-03 17:50:35 +02:00
|
|
|
|
2017-05-23 01:38:02 +02:00
|
|
|
final Logger logger = LoggerFactory.getLogger(App.class);
|
2017-04-29 16:35:57 +02:00
|
|
|
Guard guard = new Guard();
|
2017-05-03 17:50:35 +02:00
|
|
|
Thief thief = new Thief();
|
2017-04-28 19:35:19 +02:00
|
|
|
|
2017-04-29 16:35:57 +02:00
|
|
|
if (guard instanceof Permission) {
|
|
|
|
guard.enter();
|
2017-05-03 17:50:35 +02:00
|
|
|
} else {
|
2017-05-23 01:38:02 +02:00
|
|
|
logger.info("You have no permission to enter, please leave this area");
|
2017-05-03 17:50:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (thief instanceof Permission) {
|
|
|
|
thief.steal();
|
|
|
|
} else {
|
|
|
|
thief.doNothing();
|
2017-04-29 16:35:57 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-28 19:35:19 +02:00
|
|
|
}
|
2017-04-29 16:35:57 +02:00
|
|
|
|