Forum Home
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular

    My First Program (and app), CryptoKeep Portfolio

    Feathercoin Discussion
    10
    43
    7005
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Wellenreiter
      Wellenreiter Moderators last edited by

      Just got the update on my tablet and the display is ok now. Just the images are not as sharp as they probably are on a mobile, as the tablet screen is much larger and needs higher resolution of the pictures.

      Well done, aysyr :)

      [attachment deleted by admin]

      Feathercoin development donation address: 6p8u3wtct7uxRGmvWr2xvPxqRzbpbcd82A
      Openpgp key: 0x385C34E77F0D74D7 (at keyserver.ubuntu.com)/fingerprint: C7B4 E9EA 17E1 3D12 07AB 1FDB 385C 34E7 7F0D 74D7

      1 Reply Last reply Reply Quote 0
      • A
        aysyr Regular Member last edited by

        [quote name=“iawgoM” post=“28928” timestamp=“1379939899”]
        [quote author=Wellenreiter link=topic=3689.msg28923#msg28923 date=1379932799]
        Just the images are not as sharp
        [/quote]

        One thing I don’t understand - even the text part is smudgy and not sharp…how come?
        [/quote]

        Would it have anything to do with the tablet resizing the fonts? I doubt that would make a difference in clarity though right?

        And thanks Wellenreiter!

        1 Reply Last reply Reply Quote 0
        • kris_davison
          kris_davison last edited by

          I’ve just got the update too and it looks great. Thanks for the hard work.
          As a side note if you need any pointers learning Java let me know as that’s my day job. (Not touched android much tho)

          1 Reply Last reply Reply Quote 0
          • K
            Kevlar Spammer last edited by

            [quote name=“kris_davison” post=“28961” timestamp=“1379963839”]
            I’ve just got the update too and it looks great. Thanks for the hard work.
            As a side note if you need any pointers learning Java let me know as that’s my day job. (Not touched android much tho)
            [/quote]

            Orly? Do you mind if I ask you a question that most developers get really wrong in Java?

            1 Reply Last reply Reply Quote 0
            • kris_davison
              kris_davison last edited by

              Yeah go ahead!

              1 Reply Last reply Reply Quote 0
              • K
                Kevlar Spammer last edited by

                [quote name=“kris_davison” post=“28974” timestamp=“1379976181”]
                Yeah go ahead!
                [/quote]

                Ok. I’ve got the following Class structure, which I wrote myself:
                [code]
                public abstract class FileSystemNode{
                …
                }

                public class File extends FileSystemNode{
                …
                }

                public class Directory extends FileSystemNode{
                public List myNodes;
                }
                [/code]

                As you can see, File and Directory extend FileSystemNode. Directory contains 0 or more FileSystemNodes (which is to say it contains files and directories).

                Some of the methods in FSNode are common to both classes, but both File and Directory expose methods which FileSystemNode doesn’t have (files have byte arrays of their contents, directories contain other files and directories).

                Ok. So far so good. You might envision a File system specific factory which on different platforms creates and populates these differently. Whatever.

                Now I’m going to write a Backup client, which will iterate recursively through all the files and directories, and back up their contents. So I start writing code:

                [code]
                public class BackupClient{
                …

                public void backup(Directory aRootDirectory){
                for(FileSystemNode node : aRootDirectory.myNodes){
                …
                [/code]

                And… I’m stuck. I need to know if the current ‘node’ is a File or a Directory, because if it’s a file, I’ll read the bytes, but if it’s a directory, I need to recurse, and do this all over again.

                Now the thing that most developers will do is write an if statement using instance of and a cast, shown here:

                [code]
                if(node instanceOf File){
                handleFile((File) node);
                }else if(node instanceOf Directory){
                handleDirectory((Directory) node);
                }else{
                throw …;
                }
                [/code]

                This sucks for several reasons. First of all it requires a cast, which should be your first clue that you did something wrong. The entire class hierarchy of FileSystemNode has leaked into this BackupClient class, and whenever the hierarchy changes, this code is going to break, but not until run-time, when that exception gets thrown, likely on your customers machine. If my developer implemented this solution, I’d give them 1+ point for using a oft-forgotten keyword, but minus several thousand for totally breaking encapsulation and making a mess of the solution.

                So, my challenge to you is: Resolve if FileSystemNode node in our for loop is a File, or a Directory, and do the appropriate operation without using an explicit cast, or even an if/switch statement. Do this in a way that will cause the compiler to CHOKE if you add another descendant of FileSystemNode (ie SymLink, ResourceFork, whatever) without updating the code that uses it (BackupClient in this case).

                Bonus points if you can name the Gang of Four pattern that captures this solution.

                Let me know if you get stuck, I’ll give you a clue.

                1 Reply Last reply Reply Quote 0
                • kris_davison
                  kris_davison last edited by

                  Well I guess the logical starting point would be to have an abstract method (perhaps backup() )on FileSystemNode to deal with backups which would need to be implemented in each of the classes extending it.

                  In the directory class you would end up with a simple loop over its own contents and then a call to each instances own backup method.
                  And in the File class you would actually do the backup.

                  (This would also mean that any other extensions of FileSystemNode would need to implement backup() in there own way. )

                  This would be a simple solution but it would however push the Backup Logic into the File class itself which would not be ideal as you may have multiple different ways to back things up such as Copy, Compression even store in DB who knows. As for gang or four that’s not really my bag.

                  But to be fair this is hardly helpful to anyone thinking about beginning to learn Java Development and was obviously some kind of test for me to prove myself.
                  Really I don’t have any need or inclination to prove myself to anyone. Im not really in the mood for some kind of sudo Java Certification Exam.

                  On the other hand if this is a real query and you need help coming up with a solution to something I would be happy to help out.
                  But if its just a pecker comparing exercise then im quite comfortable with mine thanks very much and I don’t really care to see yours.

                  1 Reply Last reply Reply Quote 0
                  • A
                    Aldanga last edited by

                    As a former wannabe Java developer (currently .NET), I’m curious about the problem.

                    1 Reply Last reply Reply Quote 0
                    • K
                      Kevlar Spammer last edited by

                      [quote name=“Aldanga” post=“29053” timestamp=“1380043500”]
                      As a former wannabe Java developer (currently .NET), I’m curious about the problem.
                      [/quote]

                      Interestingly the solution applies equally in C#.

                      [quote author=kris_davison link=topic=3689.msg29007#msg29007 date=1380010320]
                      Well I guess the logical starting point would be to have an abstract method (perhaps backup() )on FileSystemNode to deal with backups which would need to be implemented in each of the classes extending it.

                      In the directory class you would end up with a simple loop over its own contents and then a call to each instances own backup method.
                      And in the File class you would actually do the backup.

                      (This would also mean that any other extensions of FileSystemNode would need to implement backup() in there own way. )

                      This would be a simple solution but it would however push the Backup Logic into the File class itself which would not be ideal as you may have multiple different ways to back things up such as Copy, Compression even store in DB who knows. As for gang or four that’s not really my bag.
                      [/quote]

                      That’s half way there, but as you pointed out moving the Backup logic into File really isn’t the right answer… it should remain in BackupClient. Anyone else want to chime in?

                      [quote author=kris_davison link=topic=3689.msg29007#msg29007 date=1380010320]
                      But to be fair this is hardly helpful to anyone thinking about beginning to learn Java Development and was obviously some kind of test for me to prove myself.
                      [/quote]

                      I don’t agree. Understanding polymorphism is definately a great ‘beginning Java’ subject.

                      [quote]
                      Really I don’t have any need or inclination to prove myself to anyone. Im not really in the mood for some kind of sudo Java Certification Exam.

                      On the other hand if this is a real query and you need help coming up with a solution to something I would be happy to help out.
                      But if its just a pecker comparing exercise then im quite comfortable with mine thanks very much and I don’t really care to see yours.
                      [/quote]

                      No, the point is to generate stimulating discussion and to share information. No dick waving required.

                      1 Reply Last reply Reply Quote 0
                      • S
                        svennand Regular Member last edited by

                        [quote name=“Kevlar” post=“28973” timestamp=“1379975593”]
                        [quote author=kris_davison link=topic=3689.msg28961#msg28961 date=1379963839]
                        I’ve just got the update too and it looks great. Thanks for the hard work.
                        As a side note if you need any pointers learning Java let me know as that’s my day job. (Not touched android much tho)
                        [/quote]

                        Orly? Do you mind if I ask you a question that most developers get really wrong in Java?
                        [/quote]

                        My god kevlar, a person lends out a helping hand, and the first thing you do is questioning his ability.
                        Sry mac, thats just bad.
                        Thanks for making newcomers unsure and hesitative to speak up when they feel they can contribute…

                        1 Reply Last reply Reply Quote 0
                        • Wellenreiter
                          Wellenreiter Moderators last edited by

                          Since some weeks I get an error message ‘list index too large’ and the only option is to end the application.

                          the page itself seems to come from Google, and I assume, that one of the links used for update doesn’t exist anymore

                          Feathercoin development donation address: 6p8u3wtct7uxRGmvWr2xvPxqRzbpbcd82A
                          Openpgp key: 0x385C34E77F0D74D7 (at keyserver.ubuntu.com)/fingerprint: C7B4 E9EA 17E1 3D12 07AB 1FDB 385C 34E7 7F0D 74D7

                          1 Reply Last reply Reply Quote 0
                          • kris_davison
                            kris_davison last edited by

                            I sent an error report through Google but no answer yet!

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post