Skip to content

Commit e4ae2d7

Browse files
authored
Merge pull request RefactoringGuru#6 from oleh-liskovych/master
Mediator. Minor changes; Strategy. Major changes
2 parents 4156d16 + 937a830 commit e4ae2d7

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

src/refactoring_guru/mediator/example/components/List.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public String getName() {
5959
private class Hide implements Runnable {
6060
private List list;
6161

62-
public Hide(List list) {
62+
Hide(List list) {
6363
this.list = list;
6464
}
6565

src/refactoring_guru/mediator/example/mediator/Editor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Editor implements Mediator {
2222
private AddButton add;
2323
private DeleteButton del;
2424
private SaveButton save;
25-
private refactoring_guru.mediator.example.components.List list;
25+
private List list;
2626
private Filter filter;
2727

2828
private JLabel titleLabel = new JLabel("Title:");
@@ -35,7 +35,7 @@ public class Editor implements Mediator {
3535
* RU: Здесь происходит регистрация компонентов посредником.
3636
*/
3737
@Override
38-
public void registerComponent(refactoring_guru.mediator.example.components.Component component) {
38+
public void registerComponent(Component component) {
3939
component.setMediator(this);
4040
switch (component.getName()) {
4141
case "AddButton":
@@ -48,7 +48,7 @@ public void registerComponent(refactoring_guru.mediator.example.components.Compo
4848
filter = (Filter)component;
4949
break;
5050
case "List":
51-
list = (refactoring_guru.mediator.example.components.List)component;
51+
list = (List)component;
5252
this.list.addListSelectionListener(listSelectionEvent -> {
5353
Note note = (Note)list.getSelectedValue();
5454
if (note != null) {

src/refactoring_guru/strategy/example/Demo.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* RU: Первый в мире консольный интерет магазин.
1515
*/
1616
public class Demo {
17-
public static Map<Integer, Integer> priceOnProducts = new HashMap<>();
18-
public static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
17+
private static Map<Integer, Integer> priceOnProducts = new HashMap<>();
18+
private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
1919
private static Order order = new Order();
2020
private static PayStrategy strategy;
2121

@@ -42,7 +42,7 @@ public static void main(String[] args) throws IOException {
4242
System.out.print("Count: ");
4343
int count = Integer.parseInt(reader.readLine());
4444
order.setTotalCost(cost * count);
45-
System.out.print("You wish to continue selection? Y/N: ");
45+
System.out.print("Do you wish to continue selection? Y/N: ");
4646
continueChoice = reader.readLine();
4747
} while (continueChoice.equalsIgnoreCase("Y"));
4848

@@ -59,7 +59,7 @@ public static void main(String[] args) throws IOException {
5959
// пользовательских данных, конфигурации и прочих параметров.
6060
if (paymentMethod.equals("1")) {
6161
strategy = new PayByPayPal();
62-
} else if (paymentMethod.equals("2")) {
62+
} else {
6363
strategy = new PayByCreditCard();
6464
}
6565

@@ -71,20 +71,20 @@ public static void main(String[] args) throws IOException {
7171
// т.к. только стратегии знают какие данные им нужны для приёма
7272
// оплаты.
7373
order.processOrder(strategy);
74-
}
7574

76-
System.out.print("Pay " + order.getTotalCost() + " units or Continue shopping? P/C: ");
77-
String proceed = reader.readLine();
78-
if (proceed.equalsIgnoreCase("P")) {
79-
// EN: Finally, strategy handles the payment.
80-
//
81-
// RU: И наконец, стратегия запускает приём платежа.
82-
if (strategy.pay(order.getTotalCost())) {
83-
System.out.println("Payment has succeeded");
84-
} else {
85-
System.out.println("FAIL! Check your data");
75+
System.out.print("Pay " + order.getTotalCost() + " units or Continue shopping? P/C: ");
76+
String proceed = reader.readLine();
77+
if (proceed.equalsIgnoreCase("P")) {
78+
// EN: Finally, strategy handles the payment.
79+
//
80+
// RU: И наконец, стратегия запускает приём платежа.
81+
if (strategy.pay(order.getTotalCost())) {
82+
System.out.println("Payment has succeeded");
83+
} else {
84+
System.out.println("FAIL! Check your data");
85+
}
86+
order.setClosed();
8687
}
87-
order.setClosed();
8888
}
8989
}
9090
}

src/refactoring_guru/strategy/example/strategies/CreditCard.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class CreditCard {
1111
private String date;
1212
private String cvv;
1313

14-
public CreditCard(String number, String date, String cvv) {
14+
CreditCard(String number, String date, String cvv) {
1515
this.amount = 100_000;
1616
this.number = number;
1717
this.date = date;

src/refactoring_guru/strategy/example/strategies/PayByPayPal.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void collectPaymentDetails() {
3535
System.out.print("Enter password: ");
3636
password = READER.readLine();
3737
if (verify()) {
38-
System.out.println("Data verification was successful");
38+
System.out.println("Data verification has succeeded");
3939
} else {
4040
System.out.println("Wrong email or password!");
4141
}

src/refactoring_guru/template_method/example/networks/Network.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
* RU: Базовый класс социальной сети.
77
*/
88
public abstract class Network {
9-
protected String userName;
10-
protected String password;
9+
String userName;
10+
String password;
1111

12-
public Network() {}
12+
Network() {}
1313

1414
/**
1515
* EN: Publish the data to whatever network.

0 commit comments

Comments
 (0)