Skip to content

Commit fefd46d

Browse files
committed
Refactor ComponentKey to an interface
1 parent 10d4e2f commit fefd46d

File tree

6 files changed

+46
-17
lines changed

6 files changed

+46
-17
lines changed

mvvm4fx-core/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
<groupId>org.slf4j</groupId>
1919
<artifactId>slf4j-api</artifactId>
2020
</dependency>
21-
<dependency>
22-
<groupId>com.techsenger.toolkit</groupId>
23-
<artifactId>toolkit-core</artifactId>
24-
</dependency>
2521
<dependency>
2622
<groupId>org.openjfx</groupId>
2723
<artifactId>javafx-base</artifactId>

mvvm4fx-core/src/main/java/com/techsenger/mvvm4fx/core/ComponentKey.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616

1717
package com.techsenger.mvvm4fx.core;
1818

19-
import com.techsenger.toolkit.core.Key;
20-
2119
/**
20+
* Keys are used to identify components. Component keys should be located in the API and be accessible to other
21+
* components. At the same time, the component itself can be deeply hidden in the implementation packages.
22+
*
23+
* <p>Classes implementing this interface should override toString with a meaningful representation.
2224
*
2325
* @author Pavel Castornii
2426
*/
25-
public class ComponentKey extends Key {
27+
public interface ComponentKey {
2628

27-
public ComponentKey(String text) {
28-
super(text);
29-
}
3029
}

mvvm4fx-core/src/main/java/module-info.java

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
module com.techsenger.mvvm4fx.core {
18-
requires com.techsenger.toolkit.core;
1918
requires org.slf4j;
2019
requires javafx.base;
2120
requires javafx.graphics;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2024-2025 Pavel Castornii.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.techsenger.mvvm4fx.sampler;
18+
19+
import com.techsenger.mvvm4fx.core.ComponentKey;
20+
21+
/**
22+
*
23+
* @author Pavel Castornii
24+
*/
25+
public class DemoKey implements ComponentKey {
26+
27+
private final String name;
28+
29+
public DemoKey(String name) {
30+
this.name = name;
31+
}
32+
33+
@Override
34+
public String toString() {
35+
return name;
36+
}
37+
}

mvvm4fx-sampler/src/main/java/com/techsenger/mvvm4fx/sampler/ComponentKeys.java mvvm4fx-sampler/src/main/java/com/techsenger/mvvm4fx/sampler/DemoKeys.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@
1919
import com.techsenger.mvvm4fx.core.ComponentKey;
2020

2121
/**
22-
* Component keys should be located in the API and be accessible to other components. At the same time, the
23-
* component itself can be deeply hidden in the implementation packages.
2422
*
2523
* @author Pavel Castornii
2624
*/
27-
public final class ComponentKeys {
25+
public final class DemoKeys {
2826

29-
public static final ComponentKey PERSON = new ComponentKey("Person component");
27+
public static final ComponentKey PERSON = new DemoKey("Person component");
3028

31-
private ComponentKeys() {
29+
private DemoKeys() {
3230
//empty
3331
}
3432
}

mvvm4fx-sampler/src/main/java/com/techsenger/mvvm4fx/sampler/PersonViewModel.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public PersonViewModel() {
5151

5252
@Override
5353
public ComponentKey getKey() {
54-
return ComponentKeys.PERSON;
54+
return DemoKeys.PERSON;
5555
}
5656

5757
ObservableList<Person> getPersons() {

0 commit comments

Comments
 (0)