How ngoctien0110/slang-dictionary works
Project type and purpose
• This is a standalone Java application (Console or Swing/JavaFX GUI) implementing a Slang Dictionary.
• It supports searching by slang or definition, history tracking, add/edit/delete, reset, random word, and two quiz modes.
File structure
• src/
• Main.java – application entry point
• Home.java – main menu UI
• *Page.java classes (AddPage, DeletePage, EditPage, …) – each represents a screen or dialog in the UI layer
• FileManager.java – handles all Java I/O with slang.txt and history.txt
• SlangWord.java, SlangWordList.java – data model and in-memory collection (using Java Collections, e.g., Map<String, List<String>>)
• Top-level files:
• slang.txt – initial data store of slang words and definitions
• history.txt – log of user searches
README for additional insights
• Emphasis on Java IO, Collections, OOP.
• The data must load once into a structure for fast (<1s) lookups, persist changes back to files, and preserve indexed data across sessions.
• GUI must present a menu and delegate to concrete page classes.
Main components
a. User Interface Layer
• Home (menu)
• Individual Page screens: SearchPage, SearchDefinitionPage, SearchSlangPage, GamePage, GameFindDefinitionPage, GameFindSlangPage, AddPage, EditPage, DeletePage, ManagePage, HistorySearchPage
• Each Page implements event handlers (buttons, text inputs) and calls the Controller/Service layer.
b. Controller / Service Layer
• In Main.java or a dedicated controller class: routes user actions from the UI to model operations; enforces business rules (e.g., duplicate confirmation).
c. Model Layer
• SlangWord (represents a single slang term + definitions)
• SlangWordList (in‐memory collection, indexing, search operations)
d. Data Access Layer
• FileManager (reads slang.txt into SlangWordList on startup; writes back on add/edit/delete; appends to history.txt on search).
e. External Data
• slang.txt (persistent data store)
• history.txt (search history log)
Relationships and interactions
• UI → Controller: user clicks/searches → Controller methods invoked
• Controller → Model: request search/add/edit/delete/random → Model updates or queries the SlangWordList
• Model → Data Access: on data mutation → FileManager writes changes to slang.txt
• Controller → Data Access: on search → FileManager appends entry to history.txt
• On startup: Main loads FileManager → reads files → populates SlangWordList
Architectural patterns and design principles
• Layered (UI → Controller → Model → Data Access)
• Separation of concerns:
• UI classes only handle rendering & user events
• Business logic in Controller/Service
• Data model encapsulates data structures & search logic
• Persistence abstracted in FileManager
• Use of Java Collections for fast lookup (Map for slang→definitions, List for multiple definitions)
• OOP: each page is a class, SlangWord is a value object