|
This is code design not a grammar lesson! XD But for some extent your statement is true because some of the nouns usually identify your packages or classes or the data structures you might pack into a single class. Don't rely on methods, use your brain and experience. There is no method that compensates you for not having experience so practice! practice! practice! But on my road learning code design I use the following guidline:
First you have to be able to break down a problem into small pieces, then to break down those pieces into even smaller pieces. This is the most difficult step, you need some coding experience to do this. You have to be able to identify problems and patterns. This way you get a "hierarchy of problems" a "tree of those problems". The root of this tree is your program, some nodes in the tree below the root are packages, and as you go down towards the leaf nodes you will find classes sooner or later. If you break down the problems with enough granulartiy your tree will identify the package and class structure of your program too. Of course you can start this tree from a package or class level if you have to solve only a part of the problems.
Now you have the classes and you have to find out what kind of data, which member variables are needed to solve the problems that belong to a class and you have to put them into the right class, the same is true for the methods that work with that data.
I usually spot out bad code design in a minute, this usually involves code (method(s)) that doesn't work with the member variables of the actual class the method resides in, instead the method uses data and methods that it reaches from other objects. In this case the method should be moved to somewhere else where its most used data resides. If it uses a lot of data from here and there maybe from incoming parameters (or a lot of classes call that method) then it can be put into a helper class as a static helper method.
EDIT: Another bad design is bloat code - huge monolithic classes. In this case the problem the class solves needs to be split into sub-problems and more classes.
modified 14-Jul-12 5:53am.
|
|
|
|
|
It is confusing if you concentrate on one item to the exclusion of all else. Take your example; you have a statement that "a blog entry has to have a title and a body". Okay, I can see where you are going with that, but you're now wondering whether or not you violate SOLID to have a body element AND a title element. This is designing in isolation. You need to consider the other requirements to see what effect they have.
For instance, suppose you have a requirement that states that a title must have more than 20 characters and less than 150 characters. Does this mean that you need to create a separate Title class which encapsulates the rules, or do you make it part of the BlogEntry class? Well, that depends - you might want to create a separate validation engine which is responsible for enforcing the rules, in which case you would probably just use attributes on your BlogEntry properties, so the mechanism for defining HOW to validate the properties is external, but the rules for each element are attached (this is a common technique).
Then you need to consider where your rules are applied. Do you do everything in your UI, or do you abstract to a business rules class? Is your BlogEntry class actually a model instead? Should you use MVC?
The thing I'm trying to get at here is that there is no "one size fits all" solution. As others have said, it's experience, but it is also a case that your start and end point has to be "what do I need to put in to satisfy the requirements?" By all means, consider the use cases - a well architected use case should be a vital part of developing your application because it should tell you how the user will actually use your application. Beyond that, adhering to SOLID is a mix of experience and common sense, and you shouldn't slavishly adhere to something just because someone else has written about how good it is.
|
|
|
|
|
Intelligence without being a third year undergraduate! How the fock did you do that?
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
I probably knicked it from someone clever. And I'm someone who hasn't got a computer degree - largely self taught. I don't think it's done me any harm.
|
|
|
|
|
I got my 'putin' degree only last year - after 25+ years - to find out what's new. Very little is the answer.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
I believe most of it is just fancy names for what we were doing anyway.
|
|
|
|
|
The one thing I found fascinating was Systems Theory[^]. It has nothing to do what you think and is a complete mind fock until you get the little light come on...
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
That looks interesting. I might do some digging around into that.
|
|
|
|
|
It's fun when you look at a problem domain and actually find that the best solution is to not use computers but to go back to a manual solution.
The simplest description is that you look for a single small step to improve the situation, then go back and repeat until you reach an acceptable situation without knowing what the solution will eb when you start. As I said, it's brain fick to start with until you have an epiphany.
Panic, Chaos, Destruction. My work here is done.
Drink. Get drunk. Fall over - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer
Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett
|
|
|
|
|
Now to actually give you an alternate answer...
While this is overly complicated for the question:
Body and Title could be considered types of text components and your Post could be a 'Base Object' type that consists of a component list. In this 'silly' system, your 'Post' can easily be given any number of components because Post supports having components that have their own functions.
Why not have the components as members? Well because with this idea of base objects having a list you only have to change whether you are giving the component to the object rather than modifying the member in the class. e.g. I want a new 'StupidEnemy' that has a different 'AIComponent' to the 'Enemy'. I don't have to have a new class for my new type of enemy I simply give them a different AIComponent at instantiation.
I don't think this is a great approach in most cases (As you 'could' end up using a data structure to hold a single component, this seems illogical), I’ve used it a little before and it has its pros and cons but it does mean your code fits SOLID. It works quite well for game development though as it keeps the project tidy (Relative to just using straight composition).
BaseObject post = new Post();
TextComponent Header = new Header("Header");
post.Add(Header);
Post->getComponent("Header").SetMessage("Hello World")
Post->Execute();
/rant I didn't do English at University, it has no real place in a BSc also it's more of a sociology/business idea and while it does occur, I want to aim to have a better work ethic constantly for myself!/endrant
modified 9-Jul-12 16:09pm.
|
|
|
|
|
I'm attempting automate tests using my Agilent EXA 9010A Signal analyzer. Any suggestions for doing this in Java? I am not a fan of C# and would prefer to use Java
|
|
|
|
|
|
Via the link in the other answer...look at the document tab. Then look at
"X-Series Signal Analyzer Spectrum Analyzer Mode User's and Programmer's Reference"
From there I found the following reference in the summary section
• Using the Windows XP Remote Desktop to connect to the instrument remotely
• Using the Embedded Web Server Telnet connection to communicate SCPI
The first is a possibility however the second would be what I would start with first because it is easy to do telnet. Only question is that does what it suggests and does everything you want.
If it does then you create an API for management FIRST (before doing what ever else you want.) You can either write your own telnet interface or use the Apache Commons Net component.
|
|
|
|
|
i wrote java code to read text file and when i give it word it give me its position .now i want code that when i give it a word the result will be words behind this word in same line
EX: market shop,online,web site-----data of text file in line 1
: market shop,null
when i enter "market shop"&"online" it give me "web site"
but when i enter only "market shop" it give me "null"
|
|
|
|
|
fine. You have done something wrong in there.
This is homework. So please try to solve it yourself.
You can get help for that by posting your code here (format it with the code tags).
Then we might be able to give you a hind where the problem is.
Have you debugged your code?
|
|
|
|
|
yes i debug my code.ok anyway thank you i will solve it by my self
|
|
|
|
|
what i mean that anyone give me an algorithm or idea for writing this code not give me a code ,i already think about it and i have ideas but i want another ideas that more flexible
|
|
|
|
|
algorithm ?
This is basic Java, don't make it rocket science.
Don't get me wrong: We are willing to help you. But it's our basic rule to not post solutions to homework.
|
|
|
|
|
ok and what i mean is not to solve or give me a code just all i want is steps that i applied it in code of course not code syntax .but thank you i working on my code & i will do it by my self
|
|
|
|
|
As Torsten said earlier, there is something wrong in your code, but unless you show us that code we cannot begin to guess what the problem is. Nor can we suggest any possible solutions since we have no idea how you are processing your inputs and your searches. Help us to help you, by posting the code involved in the search process, and don't forget to put <pre> tags round it so it is readable.
|
|
|
|
|
hi, I'm looking for a way to disable the minimize button in the JFrame's titlebar. I've been googling on how to solve this, I didn't get the answer that i've been looking for...
some suggestions include:
1. using a jdialog -> but the maximize button will also be hidden
2. using JInternalFrame -> but it's not the look-and-feel that i want to achieve
please help me with this one... at first, i thought it would be easy because i thought that there's a setMinimizeable or setIconifiable method for JFrame, but there isn't.
|
|
|
|
|
There is no way to do this - you will have to use JDialog.
Maximize and minimize are 2 functions that are literally combined.
Another approach would be to make the JFrame undecorated(true) and to draw some buttons yourself (and a title bar if you need a real title bar).
|
|
|
|
|
can i know how to the excel files can be imported into sql database by using java codes..
thank u
u.vinothh@gmail.com
|
|
|
|
|
What does "imported" mean?
Do you want to store the excel file itself into the database?
Or do you want to read the data from the excel file and then store that into columns in the database?
For the first option read the file in binary (bytes, not String/char) and then stream it via JDBC.
For the second, easiest is don't use java. Store the excel file as CSV then use the import features of the database to load it.
|
|
|
|
|
I have a project with Java Eclipse for android which stores data in SQLLite. My issue comes in when I include 100 lines of INSERT, it prompts me the EXCEEDED 65535 bytes.
Is it possible to place 2 "provider android:name=" in manifest then create 2 sets of the ContentProvider then make the second provider run like a continuation of the first set?
Hope you can help me. This is my first project with android. Thank you.
|
|
|
|