Posts

Showing posts from July, 2017

Enum -- just sugar to Class

Image
In Pathashala training, there was one exercise which models Metrics,Units etc. Enum was Unit, UnitSubtype. Lesson : Enum is just sugar to class.This means all the functionality which can be provided by Enum can be provided by class. In fact internally enum converted to class. Exercise : Prove above statement and change your code to use class instead of Enum. Solution : To prove : Take sample enum say Color. Get class file. In command line, run javap Color. enum Colors{ RED,GREEN,BLUE; } javap Colors Compiled from "Colors.java" final class Colors extends java.lang.Enum<Colors> {   public static final Colors RED;   public static final Colors GREEN;   public static final Colors BLUE;   public static Colors[] values();   public static Colors valueOf(java.lang.String);   static {}; } You can see declarations etc. This proves that Enum is just sugar to class.

Daily Summary -02 in ThoughtWorks Pathashala

Did pair programming: - Got to know how to work with another person while writing code. - Do ping pong( switching driver-navigator roles). - Used TDD for implementing a Rectangle class and added functionalities. Points discussed: - Only write failing test cases. - Write minimum number of test cases while ensuring a safety net. - Use good names for methods and classes that are understandable by another person. - Refractor test cases also. - Use keyboard shortcuts. (Know your IDE well) - Refractor magic numbers to meaningful constants - Use @displayName() to display a message representing test case methods in JUNIT5. - Add job of the class as a comment before the class description. It should describe the context of the class(what it represents). It should not contain class name, attribute or method names and “and” - Factory methods     * They are static methods in a class.     * They can be used to construct something and give it back.     ...

Daily Summary -01 in ThoughtWorks Pathashala

Summary Given on Date: 17 July 2017 Git is a VCS     •    We are using Gitlab     •    how to clone a repo using gitlab     •    Encapsulation is core of OOP. Using Encapsulation abstraction can be achieved but vice versa is not true. Eg. Setter method allows abstraction but breaks encapsulation     •    There are 2 types of polymorphism: Compile time(overloading) and run time(overriding)     •    Abstraction has to do with separating interface from implementation.Encapsulation has to do with disallowing access to or knowledge of internal structures of an implementation. So they are different     •    Inheritance is different from polymorphism. Inheritance is a way to achieve polymorphism but not the only way to do it.     •    Setters are different from behavior. To change a state behaviors should be used.     •    te...