Software Engineering I Sept. 11, 2013 Notes Last time we discussed inheritance More on inheritance Example: 2DShape What can you do with a 2DShape? rotate it, translate it (move it around), scale it, etc. What should be defined as abstract (i.e. the keyword in Java)? What should be implemented? What are some other specific shapes? Abstract Classes Recall that some classes (abstract classes in Java, for example) have abstract methods or operations. That is, there is no definition in the class for the method. The method definition may make sense, like rotation for a 2DShape, but it might not be possible to define it. Recall that abstract classes cannot be instantiated, and they must be declared as abstract in many languages. Overriding A Method To override a method, recall that we reimplement and replace a method from a superclass. Different reasons exist for doing so -restrictions such as violation of constraints -extension such as adding capability to existing superclasses or methods -optimization - making a method more efficient Dynamic Binding (aka virtual or late binding) This is when a program makes a decision about what class implementation to use on the fly. Dynamic binding gives polymorphism power! Don't have to write different conditions for which method from which class to use. It is very costly, though. The compiler adds extra code to deal with runtime bindings because it is not able to decide which method to call. Interfaces - in Java these are partial class implementations that are more abstract than a class. They include only abstract method definitions. How are interfaces and classes used in Java? How many interfaces can be implemented by a child class? How many superclasses can extended by a subclass in Java? Recap of OO Principles -Identity -Polymorphism -Classes -Abstraction -Inheritance +object +super/subclass -Modularity +class +interface -Encapsulation +operation +method -Information Hiding +attributes +associations Software Metrics Metrics are well-defined formulas for computing values of interest. These are often used to evaluate software engineering projects It is important to be very careful with metrics. Mark Twain said there are "lies, damned lies, and statistics." Metrics are statistics. Examples: Lines of code (LOC) or Thousands of lines of code (KLOC) Can show complexity of code. Uncommented lines of code Percentage of lines with comments # of classes # of public instance variables per class # of methods per class # of lines of code per method # of parameters per method # of overridden methods per class Depth of inheritance hierarchy Many many more. Issues with OOP Language evolution and deprecated features -Documentation is very important -JavaDoc Efficiency -VM's (e.g JVM) -Dynamic binding (overuse can cause slow programs) -Exception handling Take care when coding especially with complex code