-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenClosedPrinciple.java
70 lines (64 loc) · 1.31 KB
/
OpenClosedPrinciple.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package solidDemo;
/*
class LinkedIn {
void newPost(String message) {
if(message.charAt(0).equals("#")) {
System.out.println("It's a hashtag!");
}
else {
System.out.println("It's a general text");
}
}
}
*/
class LinkedIn
{
char extractChar (String message)
{
char s = message.charAt (0);
return s;
}
}
class Hashtag extends LinkedIn
{
public void printHashTag ()
{
if (super.extractChar ("#competitive_coders") == '#')
System.out.println ("It's a hashtag!");
}
}
class Gentext extends LinkedIn
{
public void printGenText ()
{
if (super.extractChar ("abc") != '#')
{
System.out.println ("-------------------");
System.out.println ("It's a general text");
}
}
}
class Mention extends LinkedIn
{
public void printMention ()
{
if (super.extractChar ("@zemosolabs") == '@')
{
System.out.println ("-------------------");
System.out.println ("It's @ Mention");
}
}
}
public class OpenClosedPrinciple
{
public static void main (String[]args)
{
Hashtag ht = new Hashtag ();
ht.printHashTag ();
Gentext gt = new Gentext ();
gt.printGenText ();
Mention mt = new Mention ();
mt.printMention ();
}
}
//implementing new feature is not possible,it makes our code rigid