Arlon's CSUMB Java Software Design CST-338 Module 4 Learning Journal 12 for the week Wed 03/24-Tues 03/30, year 2021

Hats off to my team this time, especially whoever wrote this:

  
               binary.append((val & 128) == 0 ? 0 : 1); 
               val <<= 1; //left bit shift, equivalent to val *= 2^1 
  

I'm still trying to figure out what the heck some of the stuff they used means - like that - in a good way - very cool. Very nice work. I just did the UML diagram and tried to patch bugs, but they beat me to every bug. They did let me give advice a few times too. I learned a lot about UML, and I still feel like I'm missing a few things, but it could be a good tool for communication. Programmers could argue nicely by sending each other UML diagrams back and forth, to a degree.

I did particularly like this assignment because it was complicated and useful! I have actually always been mystified by those QR codes, now I get it, well, I'm sure there is more to them than the assignment specifies, but overall I'm much less mystified by them now.

Learning Journal Prescribed Questions: Give an example of polymorphism and what is inherited between classes.

I think my favorite all time example of polymorphism is real life - the classification tree of life - kingdom, phylum, class, order, family, genus, species, and all the species in it. You can use that as the perfect example for all this. If you want to get a specific example, say,

abstract class Animal{public boolean eat(){/*eat*/}}
class Bird extends Animal{public boolean eat(){
   /* birds eat differently than other animals */}}
Override eat and everything else that's different! Because it's different! Birds eat differently than tigers, etc. They use their beak, tigers use their teeth, so since there are differences, override. And then just inherit whatever's not different (breath? body?) And the animal class could just be abstract. There's no 'Animal' that isn't something specific in real life. But you could do like
Dog{}
as a class, that's not abstract, and still extend it with say,
class Poodle extends Dog{}
Sometimes dogs are just dogs. You could say that for birds, bugs, lots of stuff. So you might want to not make Dog, Bird and Bug abstract - maybe there is just a Dog, a Bug, or a Bird. And sometimes, dogs are more specifically labelled, like for example, Poodles. And if it's a real friendly dog, or whatever, you could make an interface,
interface realFriendly{jumpsAround(boolean yes);}
(just a silly example) that lots of classes can inherit (implement) separately from what they inherit.

What is inherited between classes are the public and protected methods and members, but not the private methods and members.

After the learning this week, can you identify the difference between Abstract classes and Interfaces? Be specific. Yes. But not from this week, I already knew the difference. An abstract class is a class that you just can't instantiate because it's too general, like I just said about what it would be like if you made a class called 'Animal'. There's lots of animals but none of them are - just- an animal. Every type of animal is a specific type of animal. So an animal class could and should be abstract - you can never get an Animal that isn't a bird, or a dog, or some type of animal. An interface is like that, I guess, in that it isn't generally instantiated as that - although with an interface you can anonymously implement one, which is a cool trick:

interface bla{}
new bla(){};
Or with a more complete example:
public class implentAnInterfaceAnonymously{
   interface Happy{}
   public static void main(String[] args){
      
      // interface happy2{}; // Nope, for some reason you can't put interfaces directly
                                                //inside methods.
      
      new Happy(){{System.out.println("Line 203 Hello world, new Happy!");}};
                              //  implements an interface anonymously
      
     // define abstract class Animal
      abstract class Animal{public boolean eat(){return Math.random()<0.5?true:false;}}   
      
      class Cat extends Animal implements Happy{
          {      // initializer block
              System.out.println("Line 208 hello world, new Cat!");
          }      // end initializer block
          public boolean eat(){
            return Math.random()<0.75?true:false;
            /*override Animal's eat: cats eat a lot*/ }
      }      //   end Cat
      
      new Cat().eat(); // great
      
      // new Animal(); // that is not going to happen though - because the Animal class 
                                     // is abstract - you have to extend it to use it.   

      class Dog{
         // interface Friendly{} // I don't think you can do this either, 
		                                   //not inside a method.
      }      //      Dog
      
   }   /*main   */   
}   /*   implentAnInterfaceAnonymously   */

There are lots of differences. Anonymous classes can have methods - interfaces just have method declarations. A class can extend just one super class - but implement lots of interfaces. So a Cat can eat (override a superclass method) and be Happy and lots of other stuff (implement interfaces), etc.

You could define an anonymous class inside a method but I don't think you can define an interface inside a method, even if you put it in a class inside the method. Anyway there are lots of differences but I think the biggest difference is conceptually, that anonymous classes are meant to be the root of the functionality for other classes that extend them, and interfaces are meant to be added on, as many as needed, to as many classes as needed.

Update your learning journal from what you experienced this week with class.

This week I learned a lot about UML, what it is, how to make it, how to read it, what it's for, what software you can make it with, and that it gets very deep. I found diagrams.net seems like it could be used in place of Gliffy. Gliffy sent me an email validation email with no validation link - so I wasn't actually able to do the validate email instruction specified in the assignment. I also know that perhaps Inkscape could be used to make UML diagrams.

As I mentioned at the top, my favorite two lines from this weeks program are

  
               binary.append((val & 128) == 0 ? 0 : 1); 
               val <<= 1; //left bit shift, equivalent to val *= 2^1 
  
So I will remember to do some learning on bitwise operations to see if I can't gain some more insight on what is going on here.

Comments

Popular posts from this blog

Module 2 Learning Journal 1-19-21

Arlon's CSUMB ProSeminar CST300 Module 4 Learning Journal for the week Wed 1/27-Tues 2/2, year 2021

Arlon's CSUMB ProSeminar CST300 Module 8 Learning Journal for the week Wed 02/24-Saturday 02/27, year 2021 - Journal 8