Skip to content

Commit 4e92eff

Browse files
authored
Merge pull request onlyliuxin#454 from yyglider/master
work02
2 parents cb12f47 + 3e26f6d commit 4e92eff

File tree

11 files changed

+114
-0
lines changed

11 files changed

+114
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package work02.ocp;
2+
3+
public class DateUtil {
4+
5+
public static String getCurrentDateAsString() {
6+
7+
return null;
8+
}
9+
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package work02.ocp;
2+
3+
public interface Formatter {
4+
5+
String formatMsg(String msg);
6+
7+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package work02.ocp;
2+
3+
public class Logger {
4+
5+
public final int RAW_LOG = 1;
6+
public final int RAW_LOG_WITH_DATE = 2;
7+
public final int EMAIL_LOG = 1;
8+
public final int SMS_LOG = 2;
9+
public final int PRINT_LOG = 3;
10+
11+
int type = 0;
12+
int method = 0;
13+
14+
public Logger(int logType, int logMethod){
15+
this.type = logType;
16+
this.method = logMethod;
17+
}
18+
19+
Sender sender;
20+
Formatter formatter;
21+
22+
public void log(String msg){
23+
24+
String logMsg = formatter.formatMsg(msg);
25+
sender.send(logMsg);
26+
27+
}
28+
}
29+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package work02.ocp;
2+
3+
public class MailSender implements Sender {
4+
public void send(String msg) {
5+
MailUtil.send(msg);
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package work02.ocp;
2+
3+
public class MailUtil {
4+
5+
public static void send(String logMsg) {
6+
// TODO Auto-generated method stub
7+
8+
}
9+
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package work02.ocp;
2+
3+
4+
public class PrinterSender implements Sender {
5+
public void send(String msg) {
6+
System.out.println(msg);
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package work02.ocp;
2+
3+
public class RawDateFormatter implements Formatter {
4+
5+
public String formatMsg(String msg) {
6+
String txtDate = DateUtil.getCurrentDateAsString();
7+
return txtDate + ": " + msg;
8+
}
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package work02.ocp;
2+
3+
public class RawFormatter implements Formatter {
4+
5+
public String formatMsg(String msg) {
6+
return msg;
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package work02.ocp;
2+
3+
4+
public class SMSSender implements Sender{
5+
public void send(String msg) {
6+
SMSUtil.send(msg);
7+
}
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package work02.ocp;
2+
3+
public class SMSUtil {
4+
5+
public static void send(String logMsg) {
6+
// TODO Auto-generated method stub
7+
8+
}
9+
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package work02.ocp;
2+
3+
4+
public interface Sender {
5+
6+
void send(String msg);
7+
8+
}

0 commit comments

Comments
 (0)