Monday, June 29, 2009

Important object oriented terms for BCS student

setter and getter
 public int humanAge
{
get  //get accessor method
{
return age;
}
set   //set accessor method
{
age = value;
}
}
abstract and concrete
A concrete class is a simple class with members such as methods and properties. The class describes the functionality of the objects that it can be used to instantiate.

An abstract class provides all of the characteristics of a concrete class except that it does not permit objects of the type to be created. An abstract class merely defines members that are used for inheritance, defining the functionality of its child classes. These members may themselves be abstract, effectively declaring a placeholder that must be implemented by subclasses. Members may also be concrete, including real functionality, and may be marked as virtual to support polymorphism via method overriding.



class and instance
In object-oriented programming, a class is a programming language construct that is used as a blueprint to create objects. This blueprint describes the state and behavior that the created objects all share. An object created by a class is an instance of the class, and the class that created that instance can be considered as the type of that object, e.g. a type of an object created by a "Fruit" class would be "Fruit".

private, protected or public
Any code that is not intended for use outside the class should be defined as "private".

Any code that is intended for use only by objects that inherit from Mammal should be defined as "protected".
The protected keyword is a member access modifier. A protected member is accessible within its class and by derived classes. For a comparison of protected with the other access modifiers, see Accessibility Levels.

Any code that is intended for use by any other code anywhere should be defined as "public".


term signature
Methods and properties of the class

i) aggregation;

Aggregation is not the same a inheritance.Aggregation and inheritance both provide ways to create larger classes from smaller classes, but they do this in completely different ways. Aggregation is a relationship between objects, whereas inheritance is a relationship between classes.

class Wheel
{
int Diameter;
}

class Engine
{
int Cylinders;
}

class Brakes
{
int force;
}

class Car
{
theWheels[] = new Wheel[4];
theEngine = new Engine();
theBrakes = new Brakes();
}



ii) association;
Association is a (*a*) relationship between two classes. It allows one object instance to cause another to perform an action on its behalf. Association is the more general term that define the relationship between two classes, where as the aggregation and composition are relatively special.
Collapse
public class StudentRegistrar
{
public StudentRegistrar ();
{
new RecordManager().Initialize();
}
}

iii) composition;
Any 'has-a' relationships indicate the use of composition. In your code, Professor 'has-a' Student, and, Student 'has-a' professor; composition is used in both classes. Other examples are:

class Account{ Owner o; }
class Owner{ Account[] a; }

class Parent { Child c; }
class Child { Parent p; }

class CPU{}
class Computer{ CPU proc;}

iv) dependency;

For the sake of this post, I’ll use a rather naïve example. Assume, that we were building an addressbook application. This would feature an entity of type Person. In our code, we might have a class for accessing an underlying table in the database. Initially, it might look like this:


1class PersonGateway {
2 protected $db;
3 function __construct() {
4 $this->db = new PDO("mysql:host=localhost;dbname=addressbook", "root", "secret");
5 }
6 function getPerson($id) {
7 $stmt = $this->db->prepare("select * from persons where id = :id");
8 $stmt->execute(array(':id' => $id));
9 return $stmt->fetch();
10 }
11}


 class PersonGateway {   protected $db;   function __construct() {     $this->db = new PDO("mysql:host=localhost;dbname=addressbook", "root", "secret");   }   function getPerson($id) {     $stmt = $this->db->prepare("select * from persons where id = :id");     $stmt->execute(array(':id' => $id));     return $stmt->fetch();   } } 

However, we also need an entity of type Address, and since this also needs access to the database, we’ll now end up with two connections, if we implement it in the same way. What we need, is a single database object, which our two gateway classes can share. This kind of object is called a dependency[1] — The gateway classes are called dependants.

The degree that one component relies on another to perform its responsibilities. High dependency limits code reuse and makes moving components to new projects difficult. Lower dependency is better.


v) specialization.
One of the most important relationships among objects in the real world is specialization, which can be described as the is-a relationship. When we say that a dog is a mammal, we mean that the dog is a specialized kind of mammal. It has all the characteristics of any mammal (it bears live young, nurses with milk, has hair), but it specializes these characteristics to the familiar characteristics of canis domesticus. A cat is also a mammal. As such, we expect it to share certain characteristics with the dog that are generalized in Mammal, but to differ in those characteristics that are specialized in cats.


The specialization and generalization relationships are both reciprocal and hierarchical. Specialization is just the other side of the generalization coin: Mammal generalizes what is common between dogs and cats, and dogs and cats specialize mammals to their own specific subtypes.


symbols “#”, “+”, and “-“?

Object Constraint Language (OCL)
The Object Constraint Language (OCL) is a notational language for analysis and design of software systems. It is a subset of the industry standard Unified Modeling Language (UML) that allows software developers to write constraints and queries over object models. These constraints are particularly useful, as they allow a developer to create a highly specific set of rules that govern the aspects of an individual object. As many software projects today require unique and complex rules that are written specifically for business models, OCL is becoming an integral facet of object development.

Types of constraints

There are four types of constraints:

  • An invariant is a constraint that states a condition that must always be met by all instances of the class, type, or interface. An invariant is described using an expression that evaluates to true if the invariant is met. Invariants must be true all the time.
  • A precondition to an operation is a restriction that must be true at the moment that the operation is going to be executed. The obligations are specified by postconditions.
  • A postcondition to an operation is a restriction that must be true at the moment that the operation has just ended its execution.
  • A guard is a constraint that must be true before a state transition fires.

Invariant
- Constraint that applies to ALL instances of class (or type or interface)
- An expression that evaluates to true if the condition is met.
- All Invariants must ALWAYS evaluate to true.
Precondition
- Must be true at themoment the operation is to be executed.
Post Condition
- Evaluate to true at the moment the operation ends
Guard
- Must be true before state transition can occur


integration testing

Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested. A component, in this sense, refers to an integrated aggregate of more than one unit. In a realistic scenario, many units are combined into components, which are in turn aggregated into even larger parts of the program. The idea is to test combinations of pieces and eventually expand the process to test your modules with those of other groups. Eventually all the modules making up a process are tested together. Beyond that, if the program is composed of more than one process, they should be tested in pairs rather than all at once.

Integration testing identifies problems that occur when units are combined. By using a test plan that requires you to test each unit and ensure the viability of each before combining units, you know that any errors discovered when combining units are likely related to the interface between units. This method reduces the number of possibilities to a far simpler level of analysis.



topdown decomposition approach
Top-down design directs designers to start with a top-level description of a system and then refine this view step by step. With each refinement, the system is decomposed into lower-level and smaller modules. Top-down decomposition requires identifying the major higher-level system requirements and functions, and then breaking them down in successive steps until function-specific modules can be designed. Thus, top-down design is a level-oriented design approach.
Top-down design reduces the scope and size of each module, and focuses more on specific issues. It is by nature an iterative process w here each refinement will decompose a module into more specific and detailed sub-modules until it reaches a point where the "atomic" level is achieved

typed languages

structured programming and procedural programming

Procedural/Structured programming

  • Procedural Approach Data Structures can be represented as a network of associated structures, referring to one another.
  • Procedures can be represented as a network of routines which call one another, i.e., “call tree”

OOP

  • Object Oriented Approach Collection of discrete objects that incorporate data structures and behavior.
  • Each data structure has, combined with it, the procedures which apply to that data structure.
  • Contrasts with conventional programming in which data structures and behavior are only loosely connected
  • These entities, called objects, can be associated to one another in one network, rather than two.
Procedural programming is classic programming where the program language is used to tell the computer EXACTLY what do do - step by step. Examples are Assembler, Fortran, Cobol, C, etc etc. Very detailed, very difficult and time consuming to write, but very efficient from the computers point of view.

NON-procedural programming is where you tell the computer what you want, and it figures out how to get it. Non/P programming is often used for database manipulations, like SQL, Visual Basic, etc etc.

  • The interface of a class consists of its public data members and methods
Service methods are public (1), and are part of the externally accessible portion of a class
Support methods are private, and
exist to support the other methods within the class by performing some internal duties

Two possible roles of a destructor include de-allocating dynamically allocated memory (in
languages like C++) (2), and closing data files that have been opened or communication channels
such as sockets

An abstract class contains abstract methods (known as pure virtual functions in C++ or simply
as abstract methods in Java), that are incomplete. Because a portion of the behaviour of an
abstract class is yet to be defined, it is not permitted to create objects,