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 5 years ago.
Improve this question
While working on a Java web application I was wondering if my model layer was written as it should be. For instance, let's say we have a table USER in our SQL database which consists of 15 columns. Now, when we SELECT all of the columns with SQL we map it to a Java class, serialize via JSON and send it via network to some View and show it on screen.
In a second scenario, we want to select only 2 columns on screen so we do SELECT c1,c2 FROM USER. Thats where my question comes in... am I supposed to map those columns to a same Java model class? Or should i create a new mapper and class to fit it? Both of the approaches seem to have drawbacks, separate class for each query is more work, but it makes sure you always know what data it contains, rather than checking for nulls or working with optionals, also it prevents you from mapping columns you actually don't need.
What is your opinion? Thanks a lot!
Technically you could reuse the same User class for full 15-attribute as well as partial 2-attribute entity. But that will come with a price. Every time you'll see an instance of User class in the code your will have to think if it's the full entity or the partial? Which fields may or may not be null? This will make it much harder to reason about code.
Related
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 1 year ago.
Improve this question
Lets say I have class Report and I want to add a functionality printReport(...) and shouldBePrinted(...). Printing it requires GeneralPrinter and LanguageTranslator which are given from outside. Furthermore, I should add members to make the shouldBePrintable method more optimized.
The way I see it there are three ways of doing it:
The simplest is to just add the members and functions to the Report class.
Create PrintableReport which extends Report and adds those members and functions.
Use the decorator pattern to add the needed functionality. (Not sure about that one. Please correct me if this is not the correct way to use a decorator.)
Am I missing some and which is the correct method to do it?
Consider: Separation of concerns
At a HIGH level...
While it's not clear exactly what role Report fills, one might surmise it represents information organized in some fashion.
Rendering is a separate concern. Often you'll want multiple ways to render: Generate PDF, HTML, XML, and/or print (postscript, other...).
So, perhaps you have multiple classes to work with Report, GeneralPrinter, ReportPrinter, ...
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 1 year ago.
Improve this question
Data is very small like list of fruits and won't be changed often, also only one service will be using this data and serving to other services, please mention advantage and disadvantage of your approach.
I think it is better store it in a database's table.
If you store it in a enum, when you add, change or delete a fruit you have to compile your code again. In case of change, you will have to update all places (tables columns) where this fruit's name is store.
In the database you could opt to save it as a single column table or a two columns table (id, fruit_name).
I will opt the second option. Because if you choose the single column option, and you change a fruit name you will have to change it in all the tables where the fruit name is store (like in enum). A disadvantage with the two columns table is that you will have to make joins with the fruit table to get the fruit name (but make this joins is easy and simple).
I think it depends on how often there should be a change and who needs to change it. If you want the employer to be able to change them easily, you may wanna save them in the db and provide them with an api or some kind of ui so they can change whenever they want easily.
but if you yourself need to update it once each year, I see no necessity that you do not hardcode the thing.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Hey guys, I'm having a doubt about the implementation of class diagram above, confused between the Single_table strategy and the joined_table strategy, any help, any suggestion about the patterns followed in this case that are used to enhance the response time of the login process.
Any help will be appreciated.
Thank you guys in advance :).
If I got you right your concern is whether to us a table User with a flag of different Professor etc. tables. Well, I'd go for the single table. Actually there is not much difference in performance. In order to retrieve the professors from the user table you would need a WHERE clause while a native table has the records ready. The time difference in any case would be near to null as a RDBMS will handle WHERE clauses very effectively granted the DBA has set good indices. A single table is easier to maintain with respect to maintaining all the columns you need (but which your class diagram currently does not show).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
What is a CRUD table and what is it used for? Is this just another name for a hash table?
I know that CRUD stands for create, retrieve, update, and delete. Are these not just the functions of a regular DB table?
Could someone give an example, maybe in Java?
There is no CRUD table. CRUD refers to operations on a table: create, retrieve, update, and delete. Those operations can be executed on any table. They are bundled together as they are the most basic operations.
A large number of applications that people write are 'crud'. They are simply creating entries in a database, reading them, updating them, and deleting them. Managing users, bug tracking, retail stock inventories... all mostly CRUD with various business logic wrapped around it from time to time.
There isn't such a thing as a crud table. Its just the most common type of application you will find out there, and a good bet what most programmers find themselves writing time and time again.
That the name crud is synonymous with 'dirt, filth, or waste, or something of poor quality' shows part of the distain that many people have for writing such applications. On this theme, some people will jokingly refer to "Create, Retrieve, Alter, Purge" as another form of the application.
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 have near about 1 million entries in my database table and
I need to use some logic by which I can search within minimum time,
is there any algorithms or logic by which i can get result within less time.
I tried sorting table alphabetically but till it is taking much more time.
If you have any algorithm or logic then please suggest code in Java.
Looks like you need to ad in index to your database table.
If you tell what database you are using, people can give more specific help.
It dosent matter how much records you have as long as your databse is properly normalised and is having proper index. Having said that, the only difference that will make is how you are using indexes. You cannot do much in java, but your db and its design will play a significant role.