Archive for April, 2010
OOPS/JAVA UNIT 3 Costs of Inheritance
by hkesavaraju on Apr.02, 2010, under Java
Costs of Inheritance: Although benefits of inheritance are great, nothing is done without cost of any sort of inheritance. The following are considered as costs of inheritance:
1) Execution Speed: It is possible for general purpose software tools as fast as handcrafted systems. Thus, inherited methods which deal with arbitrary subclasses are slower than specialized code.
Yet, efficiency is misplaced in two aspects.
(i) the difference between speed or complexity is often small.
(iii) the reduction in execution speed may be balanced by an increase in the speed of software development..
(iii) Finally, most programmers have idea of how execution time is being used in their programs. It is like develop a working system, monitor it to discover where execution time is being is used and improve those sections.
2) Program size: Using any of software libraries for a specific project imposes a size penalty. The size of program is less important because the costs of memory were decreased. Containing development costs and producing high quality code and error free code is important than limiting the size of the programs.
3) Message Passing Overhead: Much made of the fact that passing messages is by nature a more costly operation than simply invoking procedures. As with overall execution speed, over concern about the cost of passing messages is frequently penny wise and pound foolish. For one thing, including two or three additional assembly language instructions adds a total penalty of 10%. This increased cost must be weighted against the many benefits of object oriented techniques.
4) Program Complexity: Although object oriented programming provides a solution to software complexity, overuse of inheritance can replace one form of complexity with another. Understanding the control of flow of a program that uses inheritance may require several multiple scans up and down the inheritance graph called yo-yo problem.
OOPS/JAVA UNIT 3:Benefits of Inheritance
by hkesavaraju on Apr.02, 2010, under Java
Benefits of Inheritance: The following are the benefits of inheritance:
1) Software Reusability: When behavior is inherited from another class, the code that provides that behavior doesn’t have to be rewritten. This may seem like many programmers needn’t spend much of their time in rewriting the code many times. With object oriented programming, these functions can be written only once and reused.
2) Increased Reliability: The code that is executed frequently tends to have fewer bugs than the code that is executed infrequently. When the same components are used in two or more applications, then discover the bugs in the code that exercised more than the code developed for single application. Then, latter applications gain access of those components. Similarly, the costs of maintenance of shared components can be split among many projects.
3) Code sharing: Code sharing occurs on multiple levels with object oriented programming. On one level, many users or many projects can use same classes. Another form of code sharing occurs when two or more classes developed by a single programmer as part of a project inherit from a single parent class. For instance, Set and Array are the form of collection. When this happens, two or more types of objects will share the code that they inherit.
4) Consistency of interface: When two or more classes inherit a single super class, the behavior that they inherit will be the same in all cases. Then, the interfaces to similar objects are similar and present that user is not confusing with the collection of similar objects but they have behave and interacted differently.
5) Software components: Inheritance enables programmers to construct reusable components. The goal is to develop new and novel applications. The java library offers a rich set of software components for the development of applications.
6) Rapid Prototyping: When a software is constructed from large collection of reusable components, the developers concentrate much of their time on new and unusual portion of the system. This leads to a style of programming known as Exploratory or Rapid prototyping. In this, a prototype software system is developed, users experiment with it, then produces second system with experience on first system, further experimentation tales place and so on for several interations. Such programming is useful in situations where the goals and requirements of the system are only vaquely understood.
7) Polymorphism and Frameworks: Software produced is generally written in bottom up where low level routines are written on bottom and on top of these, slightly higher abstractions are produced and on top of these, more abstract elements are generated. This process is like building a wall where every brick is laid on each already laid brick.Code portability decreases as one moves up the levels of abstraction. That is, low level routines are used in several different projects, and the next level of abstractions may be reused , but the high level routines are intimately tied to a particular application.Polymorphism permits the programmer to generate high level reusable components that can be fit in different applications by changing in their low level parts. Java awt is an example of large software framework.
Information Hiding: A programmer who reuses the component must understand the nature of the component and its interface. It is not necessary for the programmer to have detailed information concerning the techniques employed and to implement the component. Hence, the interconnected between software systems is reduced. The interconnectedness nature of software is one of the principle causes of software complexity.
OOPS/JAVA UNIT 3 Inheritance for Combination
by hkesavaraju on Apr.02, 2010, under Java
Inheritance for Combination: This form constructs a new abstraction by combining features of two or more abstractions. An example is a teaching assistant may have characteristics of both a teacher and logically behave like a student. The ability of a class to inherit from two or more parent classes is known as multiple inheritance.
Although the java language doesn’t support a sub class to be formed from two or more parent classes, approximations are taken. One such approach forms a new class that extends both an existing class and implement an interface.
An example of this is as follows:
class Hole extends Ball implements PinBallTarget
{
..
..
}
Another approach also allows a class to implement more than one interface. An example is RandomAccessFile class implementing DataInput and DataOutput interfaces.