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 4 years ago.
Improve this question
I want to create OOP - design of network application - text chat.
I use:
Java programming language
JavaFX platform as GUI
Model - View - Controller pattern
I divided my project to 3 separate packages: Model, Controller, View.
I also created class NetworkConnection, which is responsible to create connection to the server and receive/send messages.
I have several questions about application's design:
Where should NetworkConnection class belong? Model or Controller? I have been considering make this class singleton and leave it in default package. But i heard this is not the best way in OOP - design.
What is the best way to prevent NetworkConnection class from creating several instances? If there is not, what is the best place for this class in project in terms of OOP? Since this is not an object from modeling system (such as "Message", "Contact" or "Conversation") i have no idea where this class belongs in my application.
design NetworkConnection using singlton design pattern, and it will be part of you utility which will be used in the controller.
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
First of all, this is what I mean by good practice :
code that is easy to maintain / fix
code that can be scaled
an architecture that is not going to cause security issues
With this out of the way, here is my problem :
I have a User class, currently it extends the UserDetails and has additional data attached to it not relevant to security ( for example purposes, let's say I added a user description / a profile page and data ). It works well and I can log in using it.
I, however, have seen tutorials and colleagues separate the data from the user details. They have a MyUserDetails class that only does the bare bones and encapsulates a User class that is used as a data container and nothing more.
Here is a good example of what I mean ( user related classes are roughly
in the middle )
Currently my implementation "works" but I am unsure if it's good practice and am unsure if I should separate the elements contained in my own user class as I don't know if it's any better.
Any help is most appreciated.
If by UserDetails you mean org.springframework.security.core.userdetails.UserDetails class - then it's definitely good idea to separate it from your application model. Single responsibility - one of key stones of good software architecture.
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 2 years ago.
Improve this question
I'm wondering when it's not a good idea to implement a class inside MainActivity. Up until this point, I've only been using one actvitiy (Main) and so I've just been creating classes inside MainActivity.
However I'm working with more activities now and I'm planning on passing an instance of a class to another activity and back from MainActivity. Should I create a new .java file (create a new class outside of MainActivity) for this class?
What are some issues I could run into if I decide to keep my class defined in my MainActivity?
Although this question can be very opinion-based, the best practice, which has been preached several times by Google engineers and Android advocates in the annual I/O, is to keep Activity classes as simple and empty as possible. Create an architecture where functionalities are delegated into different classes, treating an Activity only as an entry point. Modularizing and abstracting your code will make it much easier to understand and maintain.
If you ask specifically about the drawbacks, then is adding unnecessary complexity into an Activity. making it is less readable and less maintainable. Of course, you can nest a class or as many as you like into an Activity, but then so that you can better decide on specific coding choices, I would recommend gaining skills in architecture design patterns, as understanding the big picture of an overall architecture will also help you to make smaller coding decisions, such as when to nest a class.
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 8 years ago.
Improve this question
in mvc what comes under what? beans, servlet and DAO. Where these tech will fit in the mvc. what will come under model, view (like jsp,html) and controller
Model: Any object that has values that need to be displayed in a view. These can be domain models, simple pojos, or anything else really. But typically the objects hold data that needs to be used in the view.
View: The thing that actually displays information to a User. In your case the JSP/HTML is considered the view. Note, a User does NOT have to be a human being.
Controller: Used to determine what Model needs to go to which View. In your case the servlet should be considered the controller.
DAO is actually part of the persistence layer, but generally it is ok for a Controller to access objects in the persistence layer and query them. You just don't want a controller writing data to a DAO. That is what services are for.
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
As I was going through this java world article, it make reference to this. I tried to look through documentation, but could not find anything.
Polymorphism is just one of the governing principles of object oriented programming.
A program that is designed in an object-oriented style is one that uses classes to encapsulate individual pieces of functionality (encapsulation) and separates design from implementation (abstraction) using interfaces and/or abstract classes.
If you like, "OOP includes polymorphism", but "polymorphism by itself is not enough to define OOP".
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 a question regarding design patterns. How can I know that which design pattern will be useful for certain modules?
I am creating a Video Conferencing system in which for database connection I have used the Singleton design pattern for one instance at the same time of database.
Now, I am creating the Chat and Video (one to many) Conference module for that which design pattern I have to follow.
What are the classes and interface I should declare for that.
Class Database
Class Chat
Class TextChat Extends Chat
Class VideoChat Extends Chat
Is that right way to declare the modules for that?
Design patterns:
each design pattern solves some problem. You need to describe the problem you have and find a matching design pattern. sourcemaking.com/design_patterns
What Singleton gives you is lazy loading of some instance and the constructor. So, you can load it based on some parameters. If multiple threads access your instance you need to synchronize them. In a static access you don't worry about loading of anything and you just pass what you need to get a DB resource. You can code DB access as number of patterns but DB access ok to be simple static stuff that any threads can access to call the data.
Database Access:
The best way to access data is through static rather than instance methods. Singleton is instance, a single instance designed for different solutions than database access.
Video conferencing software:
Are you developing Lync or Skype, etc...? Why wouldn't you just use a professionally done software for that, most of which is free?