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.
Related
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 4 years ago.
Improve this question
I am using the drag-and-drop style of GUI ( I can't write GUI code yet ).
I only know a few function like: setVisible, getText, setText, etc.
But I want to learn all the functions for the buttons or textfields that I can use
If you mean the Swing GUI:
The actual methods you can call and fields you can access in your code are exactly what you'll find in javax.swing in the Java documentation corresponding to the class you're looking at.
For example, if you have a JFrame, you can find all the methods in javax.swing.JFrame.
Properties are derived from the above Swing methods (mostly in a "remove the 'set' and 'get' manner").
For example, if you have a JFrame, you might see a background property in Netbeans, and you can find setBackground and getBackground in the documentation.
Bindings seem to be NetBeans specific, but these are also based on the properties.
For example, there's a background binding and also a background property.
Events are a bit more complicated - for example, all the mouseX events correspond roughly to addMouseListener and addMouseMotionListener, where the corresponding MouseListener and MouseMotionListener parameters has the mouseClicked, mouseEntered, etc. methods.
If you mean AWT, I imagine something similar would apply for that (but just taken from the java.awt package instead).
That's not to say every method appears in some form in the NetBeans UI - it wouldn't make sense for something like update to appear there, since that's something you need to decide when to call yourself during runtime.
Whenever you intend to study all the methods of a class, the first thing to check should be the documentation entry of that class (if exists). In general, it should contain some of the methods you are interested about and looking at the documentation entry of the parent class and the parent class of the parent class and so on should reveal all the knowledge you are interested about, therefore, this could be the learning algorithm:
define a set of classes you intend to study
open the documentation of the class
add the parent class/interface to the list described in step 1
create a list of methods you are interested about (probably you are not interested in all of them in all the cases)
go through the methods one by one
reread your lists and check whether you think there are items you might not be remembering some important details and if there are so, reread their entry. Repeat this step until there are no such items
If you already have satisfying theoretical knowledge, but you are not sure about the practice, you might want to create some small sandbox projects to try the things you just learned.
In my search for this answer I have already read the following StackOverflow post.
Definition of a Java Container
My issue (lack of understanding ) at this point as a beginner is also learning the esoteric vocabulary. Therefore, even excellent examples often make little or no sense.
For this question please create an answer for the very, very, green beginner.
The actual question:
For the "Definition of a Java Container" give a tangible example, preferably using the NetBeans project tree, of what a Java Container is. A screen-shot would be very helpful for us extremely visual learners.
For example, if I were trying to answer the question "what is a container file" to a computer 101 student, I would probably not say something like this:"A container or wrapper format is a metafile format whose specification describes how different elements of data and metadata coexist in a computer file.
Rather, I would answer like this: "A container file is a ZIP file, MP3 or MP4 file. The reason it is called a container is that it actually contains many other files - much like a directory."
UPDATE
I found this Wikipedia article that I believe begins a decent explanation.
https://en.wikipedia.org/wiki/Container_%28abstract_data_type%29
For example, according to the above article, a simple example of a "container" in a programming language is an array. In object oriented programming languages fancier arrays such a Lists and Maps are also containers. However, for any beginning programmer reading this post, containers are also Classes that form a chain of inheritance (experts correct my terminology if I am wrong).
For beginners, if you do not know what inheritance is then go study that. There is another Wikipedia article to read.This whole article is describing "containers" in Java.
https://en.wikipedia.org/wiki/Java_collections_framework
To give the sort of example I was originally asking for, if you have NetBeans then go do this:
Create a new class, then inside of it create a new method, as shown below:
package InformationStorage;
public class MyClass {
public void MyMethod(){
}
}
Now, inside the method type the command "System", and then type a period. Like this:
["Screen shot from NetBeans"][3]
Notice the list of methods and other stuff included within "System". If you choose one (for example "out" as in System.out.), then when you type the period after "out" more sub-options appear, and so on.You will eventually end with something like "System.out.println();"
This is an example of Container Classes.
Frustrated-Me this question is posed just like your name haha. Anyway I will answer. There is allot of programming jargon that will not make sense to a beginner, I wouldn't worry about it at beginner stage. So yes there is a container which is the same as say a Collection (List,Map,Set...Array is maybe one too), which just contains other data members.
But then this term is used in another way in Java and other programming languages and frameworks.
What is a container in this sense? Well I guess I would say it's complicated thing that does allot of stuff for you in layman terms. You see, something like programming a website is very complex, and Java as a programming language can be considered verbose by some, this makes for a very difficult time for a developer. So there are all these fancy frameworks, for instance: Spring which may all share some similar concepts such as dependency injection, aspect orientated programming or whatever ever else. Even if you don't know what those things are they are just ways to help the programmer develop a complicated piece of software.
These concepts are often implemented in something that may be called a container. Basically you put your POJO (instances of a java class) in this container, and the container adds functionality to what you have done, via DI, or aspect orientated programing or something else. Usually these containers are built on design patterns such as the proxy or cake or MVC ect.
One might be able to say that a container in this sense does more than just storing your objects/data, but adds additional functionality to make your life easier.
I've been developing an Android app for a while but I didn't start with any particular diagram. And now comes the time to do some real diagrams but I don't know how. Not because I'm not familiar with UML but because of Android and it's components.
For example, my app requires that the user needs to be logged in in order to see a menu. From there the user can choose the options he wants. The user can also do his registration.
Although this might be a silly and simple example...The point is...I didn't use any class named "Person" with getters and setters; or any class named "Request" with getters and setters and other methods.
My app use classes like "Login.class", "SignIn.class", "MenuActivity.class", "HistoryActivity.class".
My question is...how do I use UML for an Android app?
I mean I can't have a conceptual model diagram that says "Person"-----"Request", right?
Thanks in advance.
I think you are confused with different types of UML diagram types,
There are,
Structural UML diagrams
Class diagram
Package diagram
Object diagram
Component diagram
Composite structure diagram
Deployment diagram
Behavioral UML diagrams
Activity diagram
Sequence diagram
Use case diagram
State diagram
Communication diagram
Interaction overview diagram
Timing diagram
And more, I think you are talking about Class diagram. Since class diagrams are technical and are targeted for the development team, It is totally fine to have all these Login.class, SignIn.class, MenuActivity.class, HistoryActivity.class in your class diagram.
But you can use conceptual things like Person, Request ect in your other UML diagrams (eg Use Case). because in these diagram this is targeted for many users not just developers, So using MenuActivity does not make any sense. Using conceptual entities is the way to go here.
Good luck
Your example suggests that you're trying to capture a some sort of use case. In this case you may need an activity diagram to demostrate the higher level view or a communication diagram if you're more concerned with more detailed one.
UML isn't concerned with programming languages, platforms and so on. Its main purpose is to provide a notation which can be used to communicate ideas without necessarily getting into too much details. So the first thing you need to consider is why you need diagrams in the first place and what you want to communicate with them. Given these questions answered it will become clear what kind of diagrams you need.
There is such thing as "4+1 model" which aims to separate the software model into several views. These views show different aspects of the software and concerned with different levels of detail. In Unified Process, for example, it is adviced to model from "top" to "bottom" of the solution, from high-level overview of use cases and main features to the actual implementation details. UML supports that providing different types of diagrams as well.
So if I understood I can use those conceptual terms (Person, Request) even if they aren't any classes with those names at all...they are used as an example right?
You indeed can, but not in diagrams with low-level features like Activities. You may want to build a domain class diagram that will include Persons and other entities relevant to your application, but won't be really represented in code.
For OOP practice I am working on a hobby project, a quiz program which reads a table from txt file and asks questions about entries in the table. The idea is to have this facilitate learning of the material given for a course in our dept.
So far I wrote the I/O bit, put together a pretty modest GUI and the classes to represent the different types of entities in the datatable. I am not sure about how to proceed with the core of the program though, I mean question generation and validation.
My first idea was to have a class AbstractQuestion which pretty much defines what a question is and what fields it has (a string representation, an answer and a difficulty level). Then I thought I could write classes for different types of questions, for instance one class for simple value inquiries (like giving the name of an entity and asking for a particular property), another class for more complicated questions (for instance inquiring about interactions of entities etc).
I am not sure if this is the best way to go however. Can't really express why but I have a feeling that this is not the neatest way to go about it. Would it make sense to work on a Factory class? Essentially I need to:
provide means for a question to be generated based on one, or more, entities randomly picked from the datatable
different types of questions need to be created on the runtime, based on input from the user (desired difficulty level)
questions need to be validated and the user needs to be notified by the main Quiz class (so the questions need to be accessible).
I could start simple and implement only one type of question, get it to work and add new features in time but I think it's good practice to improve my understanding of OOP, and besides I'm afraid if it works and I start giving it out for people to test it out, I'll eventually end up working on something else. I'd like to be able to conceptualize my project better, and I think this could be a good opportunity to improve that.
PS: In case it wasn't obvious, I am not a programmer by educational background :)
You could use an Abstract Factory to create factories that know how to create questions based on specific parameters.
As for the notification you could use Observer Pattern. Study them and see examples in the language of your preference
Think in terms of two things:
What objects use Question objects? What do they need Questions to do? That is we talk about the Interface(s) of the Question.
How do Questions do those things? The Behaviour of the Question.
Initially, think only about the Interfaces. I'm not clear what we need the question to do. Seems to me that a question whose answer is free-form text and a question which offers a "Pick one of A to D" and a question which asks "Pick one or more of A to D" might well loom very different in a UI. So are you thinking in terms of "Question: please display yourself, get your answer and tell me the user's score" or "Question: what is your text? Question: what kind of answer do you take? Question : what are your four options? Question: the user entered 'a' what did they score?"
Once you've got the idea of the question's responsibilities clear, then you can consider the appropriate number of different Question interfaces and classes, and hence decide whether you need a creational pattern such as Factory. Factory works well when you have a number of different classes all implementing the same interface.
Factory: go make me a question. Question: go and ask the user.
I've got simple quiz application running on production =) There are different type of questions, with different behaviours (they should be asked, answered and tipped in different fashion). Questions have different complexity etc.
In my situation, the most appropriate solution, was creation Question superclass with some abstract methods (it could be an interface as well) and different implementation. And there were QuestionGenerator (works as a factory), factory, based on some input return different implementation.
Think, about your interface (common part) of your question and use factory pattern.
There could be more complicated scenario, where you can find some advantages of using AbstractFactory or Builder patter.
In my simple case, extracting interface was enought
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