Создана основа ооп для задач

This commit is contained in:
KamaSK 2025-05-25 17:34:48 +03:00
parent 768f7ddf37
commit 7aa394ec08
5 changed files with 81 additions and 9 deletions

View File

@ -1,9 +0,0 @@
package ru.kamask.pet;
public class TodoApp {
public static void main(String[] args) {
}
}

View File

@ -0,0 +1,18 @@
package ru.kamask.pet.todo;
import ru.kamask.pet.todo.model.SimpleTask;
public class TodoApp {
@SuppressWarnings("unused")
public static void main(String[] args) {
var task = new SimpleTask("TodoApp");
System.out.println(task);
task.markAsCompleted();
var taskData = task.data();
System.out.println(taskData);
}
}

View File

@ -0,0 +1,5 @@
package ru.kamask.pet.todo.model;
public interface DataBuilder<T> {
T data();
}

View File

@ -0,0 +1,35 @@
package ru.kamask.pet.todo.model;
public class SimpleTask extends Task implements DataBuilder<SimpleTask.Data> {
private boolean done = false;
public SimpleTask(String title) {
super(title);
}
@Override
public void markAsCompleted() {
done();
}
@Override
public boolean isCompleted() {
return isDone();
}
void done() {
done = true;
}
boolean isDone() {
return done;
}
@Override
public Data data() {
return new Data(id, title, done);
}
record Data(int id, String title, boolean done) {
}
}

View File

@ -0,0 +1,23 @@
package ru.kamask.pet.todo.model;
public abstract class Task {
private static int nextId = 1;
protected int id;
protected String title;
Task(String title) {
this.id = nextId++;
this.title = title;
}
@Override
public String toString() {
return String.format("Задача: id - %d, title: \"%s\"", id, title);
}
abstract public void markAsCompleted();
abstract public boolean isCompleted();
}