#Resources on MVC / letting java files "talk" to eachother

1 messages · Page 1 of 1 (latest)

normal ibex
#

im trying to implement MVC but my main problem is not really knowing how to let files "talk" to eachother

shadow coralBOT
#

<@&987246399047479336> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
Im trying to implement MVC but my main problem is not really knowing how to let files "talk" to eachother

In the Model-View-Controller (MVC) design pattern, communication between different components is crucial. Here are some tips on how to let Java files "talk" to each other within an MVC structure:

  1. Model: The model represents the data and business logic of the application. To allow communication with other components, you can create getter and setter methods in the model class to access and modify data.

  2. View: The view is responsible for displaying the data to the user. You can pass the model data to the view by creating methods in the view class that accept model objects as parameters.

  3. Controller: The controller acts as an intermediary between the model and view. It handles user input and updates both the model and view accordingly. You can implement methods in the controller to respond to events triggered by user actions.

  4. Observer pattern: You can use the Observer pattern to establish a communication mechanism between model and view components. The model can notify registered observers (views) when its state changes, allowing views to update accordingly.

  5. Event handling: In Java, you can use event listeners and event handlers to facilitate communication between different components. Views can raise events based on user interactions, which controllers can handle to update the model or trigger updates in other views.

By following these guidelines and utilizing Java's object-oriented features effectively, you can establish effective communication between different files in an MVC architecture.

lilac coral
#

What do you mean with talking to eachother? If you mean method invocation, that's not really MVC related and I'd recommend:

shadow coralBOT
#

For learning Java, we recommend MOOC.

It is a completely free introductory Java course created by the University of Helsinki, it is a great way to learn Java from the ground up.

Visit MOOC here:
https://java-programming.mooc.fi
(the course is available in both English and Finnish)

  • The MOOC teaches a broad introduction to programming in Java in two parts - one at beginner, and another at intermediate level.
    The end of the course is marked by creating your own Asteroids game clone!
  • The MOOC allows using features up to Java 11 - you can install Temurin OpenJDK 11 from the Adoptium project.
  • To submit exercises for evaluation, you need to configure an Editor/IDE (Integrated Development Environment) with the TMC Plugin.

The course instructions will suggest to use TMCBeans/NetBeans or VS Code for the course, but you can also use IntelliJ, which we generally recommend.

  • TMCBeans/NetBeans is the easiest to configure - but has the most dated user experience
  • VS Code is very popular as an editor, but it is quite new for Java Development. Some extra configuration is needed.
  • IntelliJ arguably has the best user experience and is most widely used Java IDE by professionals.
    IntelliJ requires installing a version no newer than 2023.1 - because the IntelliJ TMC Plugin doesn't work with newer installs.
    The IntelliJ Community version is completely free and all you need to install the TMC plugin.

To use IntelliJ with the MOOC, simply install the TMC plugin by opening IntelliJ -> File -> Settings -> Plugins and searching for TMC. You will then be able to use IntelliJ to complete MOOC.

About the course - Java Programming

normal ibex
lilac coral
#

For that I'd look more into the SOLID principles.

normal ibex
#

i probably gotta learn how to call methods first

#

im struggling a lot with that rn

pine haven
#

yeah starting with the fundamentals is a good idea, feel free to ask questions about it if needed

shadow coralBOT
#

For learning Java, we recommend MOOC.

It is a completely free introductory Java course created by the University of Helsinki, it is a great way to learn Java from the ground up.

Visit MOOC here:
https://java-programming.mooc.fi
(the course is available in both English and Finnish)

  • The MOOC teaches a broad introduction to programming in Java in two parts - one at beginner, and another at intermediate level.
    The end of the course is marked by creating your own Asteroids game clone!
  • The MOOC allows using features up to Java 11 - you can install Temurin OpenJDK 11 from the Adoptium project.
  • To submit exercises for evaluation, you need to configure an Editor/IDE (Integrated Development Environment) with the TMC Plugin.

The course instructions will suggest to use TMCBeans/NetBeans or VS Code for the course, but you can also use IntelliJ, which we generally recommend.

  • TMCBeans/NetBeans is the easiest to configure - but has the most dated user experience
  • VS Code is very popular as an editor, but it is quite new for Java Development. Some extra configuration is needed.
  • IntelliJ arguably has the best user experience and is most widely used Java IDE by professionals.
    IntelliJ requires installing a version no newer than 2023.1 - because the IntelliJ TMC Plugin doesn't work with newer installs.
    The IntelliJ Community version is completely free and all you need to install the TMC plugin.

To use IntelliJ with the MOOC, simply install the TMC plugin by opening IntelliJ -> File -> Settings -> Plugins and searching for TMC. You will then be able to use IntelliJ to complete MOOC.

About the course - Java Programming

narrow olive
#

Make your models, put them in your view, and control them with your controllers.

E.g:
Mainview would hold the actual UI
Those UI componenets will link to the controllers
The controllers determine what happens when the user does something

#

How you link them is a little different depending on what you're using

#

If you want one copy of two classes and want them to "talk" you could use singeltons

normal ibex
feral tendon
# normal ibex like the seperation of UI and the logic behind the UI for my current usecase i g...

Could build multiple Modules, inside of the project, and then have the UI in one, and the backend in another, from there, have the UI take in the backend as a Dependency, it will rely on the backend and you can then import and use calling as normal from the UI to the Backend, but not the other way around.

I personally have done a frontend, backend, shared , and service the front end (in my case I have 2, a website and a discord bot), would then use the shared for the DTO's, and the service as the dependents, so that my backend also can depend on them, and this is rambling on, use the top part of this message 😛

normal ibex
narrow olive
normal ibex
#

Im currently using fxml

normal ibex
#

i know how to connect java files to FXML but not java to java