File tree Expand file tree Collapse file tree 3 files changed +127
-0
lines changed
Expand file tree Collapse file tree 3 files changed +127
-0
lines changed Original file line number Diff line number Diff line change 1+ < Query Kind = "Program" / >
2+
3+ void Main ( )
4+ {
5+ new NavigationBar ( new Android ( ) ) ;
6+ new DropdownMenu ( new Android ( ) ) ;
7+ }
8+
9+ public class NavigationBar
10+ {
11+ public NavigationBar ( IUIFactory factory ) => factory . CreateButton ( ) ;
12+ }
13+
14+ public class DropdownMenu
15+ {
16+ public DropdownMenu ( IUIFactory factory ) => factory . CreateButton ( ) ;
17+ }
18+
19+ public interface IUIFactory
20+ {
21+ public Button CreateButton ( ) ;
22+
23+ public Button CreateButton ( ) ;
24+ }
25+
26+ public class Apple : IUIFactory
27+ {
28+ public Button CreateButton ( )
29+ {
30+ return new Button { Type = "iOS Button" . Dump ( ) } ;
31+ }
32+ }
33+
34+ public class Android : IUIFactory
35+ {
36+ public Button CreateButton ( )
37+ {
38+ return new Button { Type = "Android Button" . Dump ( ) } ;
39+ }
40+ }
41+
42+ public class Button
43+ {
44+ public string Type { get ; set ; }
45+ }
Original file line number Diff line number Diff line change 1+ < Query Kind = "Program" / >
2+
3+ void Main ( )
4+ {
5+ new NavigationBar ( ) ;
6+ new DropdownMenu ( ) ;
7+ }
8+
9+ public class NavigationBar {
10+ public NavigationBar ( ) => ButtonFactory . CreateButton ( ) ;
11+ }
12+
13+ public class DropdownMenu
14+ {
15+ public DropdownMenu ( ) => ButtonFactory . CreateButton ( ) ;
16+ }
17+
18+ public class ButtonFactory
19+ {
20+ public static Button CreateButton ( )
21+ {
22+ return new Button { Type = "Red Button" . Dump ( ) } ;
23+ }
24+ }
25+
26+ public class Button
27+ {
28+ public string Type { get ; set ; }
29+ }
Original file line number Diff line number Diff line change 1+ < Query Kind = "Program" / >
2+
3+ void Main ( )
4+ {
5+ new NavigationBar ( ) ;
6+ new DropdownMenu ( ) ;
7+ new AndroidNavigationBar ( ) ;
8+ new AndroidDropdownMenu ( ) ;
9+ }
10+
11+ public abstract class Element
12+ {
13+ protected abstract Button CreateButton ( ) ;
14+
15+ public Element ( ) => CreateButton ( ) ;
16+ }
17+
18+ public class NavigationBar : Element
19+ {
20+ protected override Button CreateButton ( )
21+ {
22+ return new Button { Type = "Default Button" . Dump ( ) } ;
23+ }
24+ }
25+
26+ public class DropdownMenu : Element
27+ {
28+ protected override Button CreateButton ( )
29+ {
30+ return new Button { Type = "Default Button" . Dump ( ) } ;
31+ }
32+ }
33+
34+ public class AndroidNavigationBar : Element
35+ {
36+ protected override Button CreateButton ( )
37+ {
38+ return new Button { Type = "Android Button" . Dump ( ) } ;
39+ }
40+ }
41+
42+ public class AndroidDropdownMenu : Element
43+ {
44+ protected override Button CreateButton ( )
45+ {
46+ return new Button { Type = "Android Button" . Dump ( ) } ;
47+ }
48+ }
49+
50+ public class Button
51+ {
52+ public string Type { get ; set ; }
53+ }
You can’t perform that action at this time.
0 commit comments