Junilu Lacar wrote:I think you've reached a point where this program is big enough that it requires some attention to design details. All the code examples you've been given in this thread, including the one I gave, is far from ideal. They are examples, yes, but frankly, they are poor examples and I think it's a bit of a disservice to you to just leave you to figure that out for yourself.
You really need to step back and think about organizing different responsibilities and assigning them appropriately to classes or objects. This goes beyond just providing some kind of authentication functionality using hashes and PINs. Guiding you down that path would be quite a journey though, I think, but I just wanted to point this out before you go any further. The last thing I'd want to see is you "learning" a lot of bad habits and saying that's what the folks at CodeRanch taught you.
Carey Brown wrote:Again, this is meant as an *example*. You will have to customize it for your particular application and replace PersistentStorage with some managed database or file.
Junilu Lacar wrote:Let me try to explain what I meant before...
Take this code:
A main entry point in a class named pin is not that great. Besides the inconsistency with Java naming conventions for class names, it really doesn't fit the intent of the code inside of it. Getting names right and putting code in right-named classes helps create context and helps you organize your thoughts around the problem. What this code tells me is that you're very focused on the PIN, which is a small detail when taken in the larger scheme of things that this program could conceivably be about. Is this supposed to be a banking app? Then why not name the main program something that communicates that better? Is login really the main focus of this program? Why make it the central idea in the main() method then?
One strong tendency that many programmers have is to dig right into the details of a problem. Try to resist that urge. Get an idea of the big picture first. Create some high-level context around your problem. Think about what are the major parts of the program you want to write. Plan, organize, and write tests as a way to visualize the end state. Then go into the nitty-gritty details of the implementation.
Martin McNicholas wrote:I would also like to ask what is the purpose of the random MD5 hash?
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|