In drawing applications, the ability to process various shapes through a unified mechanism is a core requirement. This project implements a Universal Drawing Contract using the Drawable interface. By separating the "what to do" (the draw() method) from the "how to do it" (the specific shape logic), the application achieves high flexibility. Any new shape created in the future can be integrated into the existing drawing logic simply by implementing the Drawable interface.
- Contract Definition: Established the
Drawableinterface as a standard for all renderable objects. - Interface Implementation: Realized the
draw()method within theCircleclass. - Abstract-to-Concrete Mapping: Demonstrated how an interface variable acts as a "tool" that can hold any compliant object.
- Behavioral Verification: Confirmed that invoking the interface method triggers the specific implementation logic.
- Java 8+ (Interfaces, Polymorphism, Behavioral Design)
- Drawable: The interface defining the mandatory
draw()method. - Circle: A concrete shape that fulfills the drawing contract.
- DrawingLauncherApp: The entry point for demonstrating the universal drawing tool.
Drawing a circle.
Project Structure:
JavaBasics_Task_345/
├── src/
│ └── com/yurii/pavlenko/
│ ├── app/
│ │ └── DrawingLauncherApp.java
│ └── graphics/
│ ├── contracts/
│ │ └── Drawable.java
│ └── primitives/
│ └── Circle.java
├── LICENSE
├── TASK.md
├── THEORY.md
└── README.md
Code
package com.yurii.pavlenko.app;
import com.yurii.pavlenko.graphics.contracts.Drawable;
import com.yurii.pavlenko.graphics.primitives.Circle;
public class DrawingLauncherApp {
public static void main(String[] args) {
Drawable tool = new Circle();
tool.draw();
}
}package com.yurii.pavlenko.graphics.contracts;
public interface Drawable {
void draw();
}package com.yurii.pavlenko.graphics.primitives;
import com.yurii.pavlenko.graphics.contracts.Drawable;
public class Circle implements Drawable {
@Override
public void draw() {
System.out.println("Drawing a circle.");
}
}This project is licensed under the MIT License.
Copyright (c) 2026 Yurii Pavlenko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...
License: MIT