MVC architecture in Java

Поділитися
Вставка
  • Опубліковано 17 січ 2025

КОМЕНТАРІ • 5

  • @Akhil_the_youtuber_45
    @Akhil_the_youtuber_45 Місяць тому

    Thank you sir it's help us

  • @pykchinna7783
    @pykchinna7783 Місяць тому +2

    Kunchum telugulo ardhamaiyetatlu chepochuga bro
    Telugu channel ani pettukunnav ani open chesa
    But ardhamindhele gane
    Some words Telugulo chepthe bagundu ani anthe
    Overall good
    Thank you ANNA

    • @cse.123
      @cse.123  Місяць тому

      Ok thank you

  • @Saketipavani-p9q
    @Saketipavani-p9q Місяць тому

    Example program ivvandi sir

    • @cse.123
      @cse.123  Місяць тому

      // Single program demonstrating MVC architecture
      public class MVCExample {

      // Model class
      static class Student {
      private String name;
      private int rollNo;
      // Constructor
      public Student(String name, int rollNo) {
      this.name = name;
      this.rollNo = rollNo;
      }
      // Getters and Setters
      public String getName() {
      return name;
      }
      public void setName(String name) {
      this.name = name;
      }
      public int getRollNo() {
      return rollNo;
      }
      public void setRollNo(int rollNo) {
      this.rollNo = rollNo;
      }
      }
      // View class
      static class StudentView {
      public void printStudentDetails(String studentName, int studentRollNo) {
      System.out.println("Student Details:");
      System.out.println("Name: " + studentName);
      System.out.println("Roll No: " + studentRollNo);
      }
      }
      // Controller class
      static class StudentController {
      private Student model;
      private StudentView view;
      // Constructor
      public StudentController(Student model, StudentView view) {
      this.model = model;
      this.view = view;
      }
      // Updates the model's name
      public void setStudentName(String name) {
      model.setName(name);
      }
      // Fetches the model's name
      public String getStudentName() {
      return model.getName();
      }
      // Updates the model's roll number
      public void setStudentRollNo(int rollNo) {
      model.setRollNo(rollNo);
      }
      // Fetches the model's roll number
      public int getStudentRollNo() {
      return model.getRollNo();
      }
      // Updates the view with model's data
      public void updateView() {
      view.printStudentDetails(model.getName(), model.getRollNo());
      }
      }
      // Main method
      public static void main(String[] args) {
      // Initialize the Model
      Student model = new Student("John Doe", 101);
      // Initialize the View
      StudentView view = new StudentView();
      // Initialize the Controller
      StudentController controller = new StudentController(model, view);
      // Display initial data
      controller.updateView();
      // Modify model data via the controller
      controller.setStudentName("Jane Smith");
      controller.setStudentRollNo(202);
      // Display updated data
      controller.updateView();
      }
      }