File tree Expand file tree Collapse file tree
patternBonus/src/com/premaseem Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44@author: Aseem Jain
55@title: Design Patterns with Java 9
66@link: https://premaseem.wordpress.com/category/computers/design-patterns/
7- @copyright: 2018 Packt Publication
87*/
98public class Client {
109 public static void main (String [] args ) {
11- System .out .println ("Singleton cook example " );
10+ System .out .println ("Proxy iPhone example" );
11+
12+ // Programming against interface
13+ IPhone iPhone ;
14+
15+ // Loading proxy iPhone for selection purpose
16+ iPhone = new ProxyiPhone ();
17+ phoneOperation (iPhone );
18+
19+ // Loading real iPhone for operational and sales purpose
20+ iPhone = new RealiPhone ();
21+ phoneOperation (iPhone );
22+
23+ }
24+
25+ public static void phoneOperation (IPhone iPhone ){
26+ System .out .println ("### Operations running on - " + iPhone .getClass ().getSimpleName ());
27+ iPhone .getColor ();
28+ iPhone .getDimension ();
29+ iPhone .operateDisplay ();
1230 }
1331}
Original file line number Diff line number Diff line change 1+ package com .premaseem ;
2+
3+ /*
4+ @author: Aseem Jain
5+ @title: Design Patterns with Java 9
6+ @link: https://premaseem.wordpress.com/category/computers/design-patterns/
7+ */
8+ public interface IPhone {
9+
10+ void getColor ();
11+ void getDimension ();
12+ void operateDisplay ();
13+
14+ }
Original file line number Diff line number Diff line change 1+ package com .premaseem ;
2+
3+ /*
4+ @author: Aseem Jain
5+ @title: Design Patterns with Java 9
6+ @link: https://premaseem.wordpress.com/category/computers/design-patterns/
7+ */
8+ public class ProxyiPhone implements IPhone {
9+ @ Override
10+ public void getColor () {
11+ System .out .println (this .getClass ().getSimpleName () +" Colors: Gold, Rose Gold, Carbon Black" );
12+ }
13+
14+ @ Override
15+ public void getDimension () {
16+ System .out .println (this .getClass ().getSimpleName () +" Dimension: Normal and Plus" );
17+ }
18+
19+ @ Override
20+ public void operateDisplay () {
21+ System .out .println (this .getClass ().getSimpleName () +" Sorry, This is proxy object, display will work only in Real object" );
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ package com .premaseem ;
2+
3+ /*
4+ @author: Aseem Jain
5+ @title: Design Patterns with Java 9
6+ @link: https://premaseem.wordpress.com/category/computers/design-patterns/
7+ */
8+ public class RealiPhone implements IPhone {
9+ @ Override
10+ public void getColor () {
11+ System .out .println (this .getClass ().getSimpleName () +" Colors: Gold, Rose Gold, Carbon Black" );
12+ }
13+
14+ @ Override
15+ public void getDimension () {
16+ System .out .println (this .getClass ().getSimpleName () + " Dimension: Normal and Plus" );
17+ }
18+
19+ @ Override
20+ public void operateDisplay () {
21+ System .out .println (this .getClass ().getSimpleName () +" Multi color display working in real Phone object :-) " );
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments