MVC - Controller class tutorial [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I am looking for a tutorial / book that guides me to understand the Controll functions and the best practices to write my own controller + Model
Thanks in advance.

Here are some useful links,
Model View Presenter in MSDN Magazine (To know the difference b/w Presenter and Controller look at Martin Fowler's: GUI Architecture)
MVC from Oracle
Another MVC from CodeProject
Building Graphical User Interfaces with the MVC Pattern

Im sure theres plenty of links been posted to get you started but some important factors in creating an MVC is:
Static Registry Class (Store objects and fetch with a global scope)
Router (A class that determains the controller/method and params from URI's)
Base Controller (just a small abstract class then the users controller can extend)
SPL Auto-loading (this will allow users to extend classes such as Model_Database)
Structure (you should create directories in accordance with names, I.e Library_session would load /library/session.class.php)
Model Abstraction (Account for all types of storage, Database, Disk etc)
Error Tracking (Always make sure your logging and capturing errors)
They are just a few tips and ideas you should be thinking about when you create your system.
What you should also do is user other frameworks and build some sample projects, learn how an MVC Framework should be sued, so when your building one you know what the user should expect, then just really study the core structure of the framework.
Take into consideration in PHP the following are usually how MVC Works
Controller (this is executed depending on the URI)
Model (Accessed from the controller and should be the I/O of Data)
View (Templates basically)
but you can work with a MVCL which is (M odel/V iew/C ontroller/L language)
Language is not a specific in the original documentation but its been adopted a few times in regards to the pattern structure, An example of the file structure below will guide you into whats the main purpose of the +L
M: \catalog\model\catalog\product.php
V: \catalog\view\template\product\product.tpl
C: \catalog\controller\product\product.php
L: \catalog\language\english\product\product.php
An example of what company / project uses this method is: OpenCart, AND I HIGHY RECOMMEND YOU LOOKING AT THE ARCHITECTURE!

Here is a hopefully helpfull link to an article.
and here is a link to a very descriptive tutorial.

Why not trying codeigniter?
It is a Model View Controller based Framework.
In combination with doctrine its pretty usefull.
Here the link to some codeigniter tutorials: codeigniter tutorials

You're question basicaly a design patern question, a realy good book about this subject is:
Architect's Guide to PHP Design Patterns

Related

Draw sequence diagrams for a Java Swing application [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 days ago.
The community is reviewing whether to reopen this question as of yesterday.
Improve this question
I have a simple ATM system implemented in Java using Swing (I know Swing isn't really used anymore but I wanted it to be simple). The way I implemented it is as follows:
I have a Customer class which holds information about a customer and has a login() method
I have an Account class which holds information about an account and has methods for withdrawing, depositing and transferring money
I have a Transaction class which holds information about a transaction and has a generateReceipt() method that creates and exports a PDF with transaction info
I have an ATM class which holds the logged in account and the corresponding customer and has static methods for getting transactions, such as the current account transactions
Finally, I have an Admin class with username and password as attributes and methods for getting all the customers and accounts, adding a customer or creating an account and deleting a customer or an account.
My application uses a MySQL database for storing information and making updates. Also, customers can have multiple accounts and one can log in the system using the account number and PIN.
I drew the use case diagrams, and the class diagram, not considering my UI in the class diagram.
I have a hard time creating sequence diagrams for this application, as all my classes and objects are used in classes made with Swing.
My question is: how should I structure my sequence diagrams, considering the fact that it is a Swing application? Should I add the UI classes or should I make it more conceptual and only describe the process and relations between my other 5 classes?
Any help is highly appreciated!
I tried separating as much logic from the actual UI, but I still can't figure out how should my sequence diagrams look, as a customer and the admin interacts with the Swing frames.
The class diagram without any of the app's internals is a "domain model". Its goal is not to document all possible classes used in your apps, but to focus on the domain knowledge, independently of how the app is implemented. The diagram would stay the same if you had a real ATM device, if you would implement a web service, or if you would use any other UI framework.
So you made a clear choice on what you wanted the diagram to show. You could perfectly have chosen to have monstrous class diagram including in addition the classes required for the business logic, for database interaction and for the UI (e.g. using the famous Entity Boundary Control pattern). The diagram would then be more dependent on your implementation choices.
For the sequence diagram, it's the same. There is no best way to draft this diagram. The question is only about what you want this diagram to focus on: do you want to model the domain logic ? In this case you would use your domain classes and show how they interact. Or do you want to model the detailed application design , in which case you could envisage to add also UI classes. But the diagrams would then quickly become very complex, and you'd better break them down into several simpler SDs, each focusing on some parts of your detailed technical design.

Can a Plain Old Java Object/POJO have methods that deal with business logic other than getter/setter methods? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 months ago.
Improve this question
Can a Plain Old Java Object have methods that deal with business logic other than just the getter/setter methods?
I see possibly mixed answers for this so is there no rigorous definition for this? I know a POJO cannot implement an interface, extend a class, and not use annotation.
You seem to be getting caught up in details of a formal definition that does not exist.
“POJO” is not a precise formal term. “POJO” is a catchy casual term coined by Martin Fowler, Rebecca Parsons, and Josh MacKenzie back in 2000.
The idea of a POJO is an object that is not enmeshed in a complicated framework. Any experienced Java programmer should be able to read and understand the source code of a POJO without needing to learn some framework, and without needing to look up third-party documentation.
Annotations
So, a POJO will generally have few annotations only because because Java bundles few annotation classes. Most annotations come from external frameworks. So if we are avoiding the complications of external frameworks, we are avoiding most annotations.
Personally, I would add an exception for one framework: Jakarta Bean Validation (Wikipedia). This framework is relatively simple, does not involve any elaborate involvement, and focuses on the validity/integrity of the POJO’s own internal field values. The validation rules are applied as annotations.
Logging might be another framework exception. And maybe Java Management Extensions (JMX) monitoring too. Notice that all three of my own personal choice in framework exceptions are focused on the POJOs themselves, as opposed to orchestrating some elaborate involvement with other objects.
Business logic
And, yes, a POJO can have business logic, especially regarding its own internal state, and regarding its need to communicate its changes with the outside world such as persisting data and notifying other interested parties.
Indeed, you can learn about:
Hexagonal Architecture by Dr. Alistair Cockburn(and related variations, Onion Architecture, etc.)
Domain-driven design (see book by Eric Evans)
… to see how you can use POJOs as domain objects (“business objects”, with core business logic) while keeping them separate and protected from various elaborate frameworks operating in other parts of your app.
Data-only objects
Some classes are intended to simply carry data. All such data-only classes are POJOs. But not all POJOs are data-only classes.
I suggest you learn about Data Transfer Objects and Value Objects, as kinds of data-only classes.
If the main purpose of your class is to communicate data transparently and immutably, use the records feature in Java 16+. In a record, by default, the compiler implicitly creates the constructor, getters, equals & hashCode, and toString.
And let me be clear: there is nothing wrong necessarily with elaborate complicated frameworks. They can be exquisitely useful, obviously. That's why they were invented. Each framework has a purpose and a place.
The term POJO was invented so that in discussions about programming and system architecture/design we can make the distinction between classes that are simple and not entwined versus those classes that are complicated and entwined.

tridium niagara 4 dropdown in baja.jar

There is one software Tridium Niagara 4, which is private not opensource. This software put everything secure. No documentation for development troubleshooting and the documents are also clumsy, they are not in simple words.
For non programmers it is miry pit. I have been given the task for GPIO port on one device. We have our own API in .cpp , which is tested and is working.
Backend is working fine with all native callbacks but now we need to create GUI for GPIO. And we need combobox instead of textblock so we can restrict user from entering random values.
We tried with following command but not working any idea?
#NiagaraType
#NiagaraProperty (
name = "direction",
type = "bajaui:BListDropdown",
defaultValue = "in"
)
This software provides info from Tridium(name of the company) only, and they call the developers who use their software - "Niagara Developer". I hope they will give suggestions or answer on stack overflow sites.
You can't have a UI element as a Niagara property like this. In your case, the property probably needs to be a class that you develop which extends BFrozenEnum - in other words, the property is really the data model if you want to think of it in terms of the MVC programming paradigm. The dropdown you describe would instead be a widget inside a Px file, workbench view or something similar which would render the enumerated value of your BFrozenEnum.
In terms of the wider scope of your question, there is a Tridium business model whereby anyone who wants to develop using Niagara should really be thinking about certification. Niagara isn't simply just Java + UI: it is a complete framework built on top of the bare bones language and (I speak from personal experience) you need to have a thorough grounding & training in it before you can make any progress. That developer training, for instance, would explain how you implement a BListDropDown and similar widgets to render your data, and would take you on a tour of the developer documentation.
That same business model I just described also provides developers with technical support (not about Java, but about how you program and extend the framework), but the support has to be paid for. As another response has already said, you can of course expect general Java questions to be answered in StackOverflow, but the only answers to framework-specific questions posted here will come from interested Niagara developers like myself, not from the Tridium corporation itself.
Sorry that I can't be of more assistance.

Implementing UML diagram to Java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How would I go about implementing/converting this UML diagram to Java code? Do I have to use constructors?
Here is the diagram:
Answer to your Question: No you dont have to use constructors, none of the classes shows one so youre fine with just the default constructors beeing generated while compiling.
Here is what you can do based on the assumption that this pictures information is stored in a understandable format (like for example extracted from IBMs Enterprise Architect).
1.) Learn Java so you can transform for example the box "CEO" into this:
public class CEO extends Employee{
#Override
public void printDetails(){}
}
2.) Use a IDE/ Tool that can generate such class skeletons based on your diagramms information. ArgoUml, Enterrpise Architekt, BlueJ, IntelliJ and stuff, just google for "java uml to code"
3.) Write a Tool that parses UML pictures metadata and generates the appropriate code.
In your case you probably want to go for 2.) and then hire a application developper to fill the generated skeletons with functionality.
Edit: As other comments suggested there is a problem with your diagramm. Before programms like in 2.) above can parse the information to generate class skeletons it must be understandable what the relations (arrows) in your diagramm express. Look at the relation between for example Office and Departement. I as a human can interpret this as "yeah that arrows probably do tell that a office extends from a Departement rather than telling me that a Departement has a reference to a Office and vice a verse". But that a tool can make this decission it must be clear what of both is meant. Usualy this arrows would suggest both classes holding a references to the other one and you probably rather want a single arrow pointing from Office to departement that has a Label "extends" or "implements" attached.
First of all, you will have to understand what each notation in UML means based on which you can convert those to java classes.
Below is a nice article that attempts to explain.
http://java.dzone.com/articles/uml2-class-diagram-java
Use UML tool ArgoUML. It is based on java. ArgoUML is the leading open source UML modeling tool and includes support for all standard UML 1.4 diagrams. Default constructors is a good practice as in some case like singleton pattern you have a private constructor.

MVC with swing implementation java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am confused how MVC will work with GUI swing application. I have worked with PHP MVC but that is totally different. I understand what MVC stands for. But what making me confused is different variation of doing it in GUI swing programming. It is hard to conclude particular thing from different articles in web. Who should know whom? I mean what will be the relation between model view and controller? Should controller know both model and the view? I would like to an simple example if possible to illustrate this (like and simple button which will update a label)
If i am not asking more i would like to get sugetions of MVC book which is writtern Swing in mind.
If you ask 10 different people "What does MVC mean?" you'll probably get 10 different answers. I'm personally partial to this definition of MVC (at least for non-web apps):
Model-View-Controller Design Pattern
Basically, the only functions the controller serves is to instantiate model and the view as the application starts up and connect them to one another. Everything else is just proper decoupling of your program's data and logic (model) from how you choose to display it to the user and allow user interaction (view).
There are many different interpretations of MVC for Java. I will try to provide a basic explanation, but as I said, others may disagree on this.
A theoretically 'pure' interpretation of MVC involves the following:
Model does not know about view
View does not know about model
Controller connects model and view in such a way that it provides data from the model to the view, handles 'events' in the view or the model, and updates the model accordingly based on what is happening in the view. It can also just handle an event in the view and provide a result back to the view, for example, a calculator.
Here is a possible/simple example:
The goal of this hypothetical application is to take a String in the model, get it to the GUI (view), allow the user to change the string, and update the aforementioned String value in the model. This example is more or less as decoupled as possible.
Model:
Contains a String variable
View:
Displays String variable.
Takes user input that allows change to the String.
Controller (the 'glue'):
Listens to Model via a customized listener for the String.
Provides this String to the view for the user to see
Listens to the view via a customized listener for the user to change the String.
Takes this new String and provides it to the Model, updating the original String.
One of the key things behind MVC is the Observer Pattern Theory.
Although one takes certain risks using wikipedia, it generally does a good job conveying the basics behind MVC. http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
Here is the link for a discussion on the 'pure' implementation and the source of the interpretation.
http://www.youtube.com/watch?v=ACOHAR7PIp4
Here is a link with a very good explanation of a similar MVC interpretation and the theory behind it:
http://www.youtube.com/watch?v=CVxt79kK3Mk

Categories