Encapsulation is not just about hiding data, but about managing access to it. In this project, we implement Getters—special methods that act as safe bridges to our private fields. We also introduce a Parameterized Constructor, which allows us to set the initial state of the Person object at the moment of birth. This design pattern ensures that once a club member is registered, their data is protected from accidental external modification while remaining accessible for reading.
- Private Field Protection: Fields remain inaccessible from outside the class.
- Getter Implementation: Added
getMemberName()andgetMemberAge()for read access. - State Initialization: Used a constructor to populate private fields.
- Clean API: The
Solutionclass interacts only with public methods, not raw data.
- Java 8+ (Encapsulation, Getters, Constructor Injection)
- Person: The Model. Encapsulates state and provides an interface for retrieval.
- ClubReporter: The View. Formats and prints member details using getters.
- SolutionApp: The Entry Point. Orchestrates member creation and data display.
[CLUB INFO]: Member details retrieved via Getters:
Name: Anna
Age: 30
Project Structure:
JavaBasics_Task_245/
├── src/
│ └── com/yurii/pavlenko/
│ ├── Person.java (Model with Getters)
│ ├── ClubReporter.java (Console Output)
│ └── SolutionApp.java (Entry Point)
└── README.md
Code
package com.yurii.pavlenko;
public class SolutionApp {
public static void main(String[] args) {
ClubReporter reporter = new ClubReporter();
Person anna = new Person("Anna", 30);
reporter.printMemberInfo(anna);
}
}package com.yurii.pavlenko;
public class Person {
private String memberName;
private int memberAge;
public Person(String name, int age) {
this.memberName = name;
this.memberAge = age;
}
public String getMemberName() {
return memberName;
}
public int getMemberAge() {
return memberAge;
}
}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