{"id":30845457,"url":"https://github.com/tharindu714/visitor-pattern-shapes-app","last_synced_at":"2025-09-06T23:10:49.238Z","repository":{"id":309554005,"uuid":"1036685629","full_name":"Tharindu714/Visitor-pattern-Shapes-App","owner":"Tharindu714","description":"Compute areas cleanly — without changing your shape classes. A lightweight, educational, and visually delightful Java Swing application demonstrating the Visitor design pattern to compute areas for multiple shape types (Circle, Square, Triangle) while keeping code open for extension.","archived":false,"fork":false,"pushed_at":"2025-08-12T13:34:32.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-12T15:30:23.373Z","etag":null,"topics":["java","oodp","visitor-pattern"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tharindu714.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-12T12:43:57.000Z","updated_at":"2025-08-12T13:43:46.000Z","dependencies_parsed_at":"2025-08-12T15:40:40.702Z","dependency_job_id":null,"html_url":"https://github.com/Tharindu714/Visitor-pattern-Shapes-App","commit_stats":null,"previous_names":["tharindu714/visitor-pattern-shapes-app"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Tharindu714/Visitor-pattern-Shapes-App","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tharindu714%2FVisitor-pattern-Shapes-App","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tharindu714%2FVisitor-pattern-Shapes-App/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tharindu714%2FVisitor-pattern-Shapes-App/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tharindu714%2FVisitor-pattern-Shapes-App/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tharindu714","download_url":"https://codeload.github.com/Tharindu714/Visitor-pattern-Shapes-App/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tharindu714%2FVisitor-pattern-Shapes-App/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273974082,"owners_count":25200587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","oodp","visitor-pattern"],"created_at":"2025-09-06T23:10:47.758Z","updated_at":"2025-09-06T23:10:49.226Z","avatar_url":"https://github.com/Tharindu714.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🧮 VisitorShapesApp — Elegant Area Calculation with Visitor Pattern\n\n\u003e **Compute areas cleanly — without changing your shape classes.**\n\u003e A lightweight, educational, and visually delightful Java Swing application demonstrating the **Visitor design pattern** to compute areas for multiple shape types (Circle, Square, Triangle) while keeping code open for extension.\n\n---\n\n## 🚀 Highlights (Why you’ll love this)\n\n* **Pattern-first** — teaches the Visitor pattern with real UI interactions. 🔍\n* **Interactive GUI** — add shapes, compute single or total area, and observe visitor calls in the activity log. 🖱️\n* **Single-file, instance-based** — everything implemented as instance inner classes, easy to read and reuse. 🧩\n* **Educational \u0026 production-ready** — perfect for demos, teaching, or as a starter template for graphics/geometry apps.\n\n---\n\n## ✨ Features\n\n* Add circles, squares, and triangles via friendly dialogs. ➕\n* Compute area for a selected shape with `AreaVisitor`. ▶️\n* Compute the total area of all shapes by iterating and visiting each. Σ\n* Activity log with timestamps and emoji badges. 🧾\n* Clean, responsive Swing layout with custom cell rendering for shape list. 🎨\n\n---\n\n## 🧠 Visitor Pattern — Theory (Plain English)\n\nThe **Visitor design pattern** separates algorithms from the objects on which they operate. Instead of adding new behavior to many classes (which violates the Open/Closed Principle), we define a **Visitor** that implements operations for each concrete element type.\n\n**Core participants:**\n\n* **Element (Shape)** — declares `accept(Visitor)`.\n* **ConcreteElement (Circle, Square, Triangle)** — implements `accept` and delegates to the visitor.\n* **Visitor (AreaVisitor)** — declares visit methods for each concrete element type and performs the operation.\n\n**Why use Visitor here?**\n\n* You can add new operations (e.g., perimeter, bounding box) without modifying shape classes.\n* Each operation is centralized in one place (visitor), improving maintainability and extensibility.\n\n---\n\n## 🔗 How the Visitor Pattern is applied in this project\n\n* **`Shape`** (interface) — declares `accept(Visitor)` and `getName()`.\n* **Concrete shapes** (`Circle`, `Square`, `Triangle`) — each implements `accept(Visitor)` by calling the corresponding `visit(this)`.\n* **`Visitor`** (interface) — declares `visit(Circle)`, `visit(Square)`, `visit(Triangle)`.\n* **`AreaVisitor`** — concrete visitor that computes and stores the last computed area. The GUI calls `accept(areaVisitor)` on shapes to compute results.\n* The GUI demonstrates **double-dispatch**: `shape.accept(visitor)` → `visitor.visit(concreteShape)` so the right method is selected at runtime without `instanceof` checks.\n\n---\n\n## 🛠 Build \u0026 Run\n\n**Prerequisites**\n\n* JDK 8+ installed.\n\n**Compile \u0026 run**\n\n```bash\njavac VisitorShapesApp.java\njava VisitorShapesApp\n```\n\nIf you split classes into files, compile all `.java` files in the same directory:\n\n```bash\njavac *.java\njava VisitorShapesApp\n```\n\n---\n\n## 🧭 Usage Walkthrough (quick demo)\n\n1. Launch the app — you’ll see a list area, control buttons, and an activity log. ✅\n2. Click **Add Circle / Square / Triangle** to create shapes with custom sizes. ➕\n3. Select a shape in the list and click **Compute Selected Area** — the app uses `AreaVisitor` to compute the area and logs the result. ▶️\n4. Click **Compute Total Area** to run the visitor across all shapes and display the sum. Σ\n5. Inspect the activity log to see how visitors are invoked — it’s a great teaching aid. 🧾\n\n---\n\n## 📐 UML Diagram\n\n\u003e **Paste your PlantUML or image here**\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"757\" height=\"685\" alt=\"image\" src=\"https://github.com/user-attachments/assets/7d64396b-dd68-4e4a-8d7c-ac95857c10cb\" /\u003e\n\u003c/p\u003e\n\n---\n\n## 📸 GUI Screenshot\n\n\u003e **Insert your GUI screenshot here**\n\n\u003cimg width=\"1075\" height=\"651\" alt=\"image\" src=\"https://github.com/user-attachments/assets/62234ac3-2e8b-432d-82a7-dfe5c2a7cdd1\" /\u003e\n\n---\n\n## 🔧 Code Structure (conceptual)\n\n```\nVisitorShapesApp (main)    -\u003e builds UI and demonstrates visitor usage\nShape (interface)          -\u003e accept(Visitor), getName()\nCircle, Square, Triangle   -\u003e concrete elements (implement accept)\nVisitor (interface)        -\u003e visit(Circle), visit(Square), visit(Triangle)\nAreaVisitor                -\u003e computes area (visit methods)\nDialog classes             -\u003e UI helpers to add shapes\nCell Renderer              -\u003e nicer list display\n```\n\n---\n\n## 💡 Extensions \u0026 Next Steps\n\n* Add `PerimeterVisitor` or `BoundingBoxVisitor` to showcase multiple operations. 🔁\n* Export shapes and computed metrics to JSON/CSV. 📤\n* Add a drawing canvas to display shapes graphically and interactively. 🖼️\n* Integrate unit tests for Visitor logic (e.g., area formulas). 🧪\n\n---\n\n## 🧾 License \u0026 Credits\n\nUse this as you like — attribution appreciated. Suggestion: add an `LICENSE` file (MIT) if you plan to publish.\n\n---\n\n## 🎉 Final Notes\n\nThis app is designed to be both an effective learning tool and a polished demo. Paste your UML and screenshot in the placeholders above, and you’ll have a presentation-ready README that’s both **professional** and **approachable**. Want me to paste a PlantUML diagram into the UML section now?\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftharindu714%2Fvisitor-pattern-shapes-app","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftharindu714%2Fvisitor-pattern-shapes-app","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftharindu714%2Fvisitor-pattern-shapes-app/lists"}