![]() |
|
[Java] Java Contact Recorder - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Java] Java Contact Recorder (/showthread.php?tid=5868275) |
Java Contact Recorder - Consulting Detective - Jul 31, 2018 It has been 2 weeks since I last posted in the Java section. I have learned heaps since then. Constructors, encapsulation, polymorphism, composition, inheritance, pass by value vs pass by reference and so on. Right now I'm practicing ArrayLists. Just want to share something I made. It is a simple phonebook, it can search, add, delete and modify contacts. I know there is no input sanitation in my code, but I'm getting my hands dirty on that later. PHP Code PHP Code RE: Java Contact Recorder - hash - Jul 31, 2018 Congratulations on your improvement! Some things that you can eventually improve on is that you don't want your logic to be spread out. In your main especially case 4 there is a lot of logic involved. You probably want to make it either a function or let another class or function handle it. Also what happens when I insert 2x the same name? ;) What happens when you spread logic is that when you change your scan class or want to modify something in terms of contacts the code fails in multiple classes. Also if you're busy with ArrayLists check how to make your own! I cannot post any links yet but search for Java Enumerator class. It's fun to play around with that as well! RE: Java Contact Recorder - Tenno - Jul 31, 2018 If you want to write a bit more generic, you can declare an arraylist like this: PHP Code So if you want to change it to a LinkedList for example, you just type new LinkedList instead of ArrayList. Anyways, you've definitely improved! RE: Java Contact Recorder - Consulting Detective - Aug 1, 2018 (Jul 31, 2018 03:11 AM)Alluminition Wrote: Congratulations on your improvement! Some things that you can eventually improve on is that you don't want your logic to be spread out. In your main especially case 4 there is a lot of logic involved. You probably want to make it either a function or let another class or function handle it. Also what happens when I insert 2x the same name? ;) Case 4 does look a bit cluttered. Guess I need to learn which code should be a separated and be implemented as a method instead. But doesn’t that ruin the pattern I have? If I’m going to put the logic of a case in a method? Maybe I should do the same for all the other cases? (Jul 31, 2018 08:39 AM)Tenno Wrote: If you want to write a bit more generic, you can declare an arraylist like this: Thanks :) I haven’t looked at linked lists yet. I will do that now. Holy shit. I just made my own int ArrayList. This is awesome. PHP Code RE: Java Contact Recorder - hash - Aug 1, 2018 (Aug 1, 2018 12:33 AM)Consulting Detective Wrote: Case 4 does look a bit cluttered. Guess I need to learn which code should be a separated and be implemented as a method instead. But doesn’t that ruin the pattern I have? If I’m going to put the logic of a case in a method? Maybe I should do the same for all the other cases? For now it's okay since it's not a very complicated method. But if you are going to add input validation you can make a method for that and re-use it for all inputs. Another tip is to always comment a method or case. What goes in and what will be returned. It's a good thing to start with early because commenting is not as easy as it looks. If you want to study more in-depth about programming in Java study Gang of Four patterns and Applying UML and patterns. Helps to program in a more professional way. |