Pages

Showing posts with label Object Oriented Systems. Show all posts
Showing posts with label Object Oriented Systems. Show all posts

Monday, November 12, 2012

MCA OOS UNIT 4 & UNIT 5



Inheritance
C++ strongly supports the concepts of reusability.
Once a class has been written and tested, it can be adopted b other programmers to suit their requirements.
This is basically done by creating new classes reusing the properties of the existing once.
The mechanism of deriving a new class from an old one is called inheritance.
The old class is referred as base class and the new one is called the derived or subclass.
Hierarchical Inheritance
Multilevel Inheritance

Multiple Inheritance
Hybrid Inheritance

Single Inheritance



A class can also inherit properties from more than one class or from more than one level .
A derived class with only one base class is called single inheritance and one with several base classes is called multiple inheritances.
The traits of one class may be inherited by more than one class. This process is called as hierarchical inheritance.
The mechanism of deriving a class from another derived class is known as multilevel inheritance.




Syntax 

class  derived_ class-name : visibility-mode  base class_name
{
---------------//
---------------//members of derived class
--------------//
} ;

Single Inheritance Example :Single Inheritance is method in which a derived class has only one base class.

#include <iostream.h>
class Value 
  {
    protected:
      int val;
    public:
      void set_values (int a)
        { val=a;}
  };
class Cube: public Value 
  {
    public:
     int cube()
       { return (val*val*val); }
  };
int main () 
 {
   Cube cub;
   cub.set_values (5); //object of cube class inherit the 
                         function of Value class 
   cout << "The Cube of 5 is::" << cub.cube() << endl;
   return 0;
 }

Multiple Inheritance Example: Multiple Inheritance is a method by which a class is derived from more than one base class.

#include <iostream.h>
using namespace std;
class Square
  {
    protected:
     int l;
    public:
     void set_values (int x)
      { l=x;}
  };
class CShow 
  {
    public:
     void show(int i);
  };

void CShow::show (int i) 
 {
   cout << "The area of the square is::" << i << endl;
 }

class Area: public Square, public CShow
  {
   public:
    int area()
      { return (l *l); }
  };
int main () 
{
  Area r;
  r.set_values (5);
  r.show(r.area());
  return 0;
}


Hierarchical Inheritance Example: Hierarchical Inheritance is a method of inheritance where one or more derived classes is derived from common base class.

#include <iostream.h>
class Side
  {
    protected:
      int l;
    public:
      void set_values (int x)
        { l=x;}
  };
class Square: public Side
  {
    public:
      int sq()
      { return (l *l); }
  };
class Cube:public Side
  {
   public:
     int cub()
      { return (l *l*l); }
  };
int main () 
  {
    Square s;
    s.set_values (10);
    cout << "The square value is::" << s.sq() << endl;
    Cube c;
    c.set_values (20);
    cout << "The cube value is::" << c.cub() << endl;
    return 0;
  }


Multilevel Inheritance Example: Multilevel Inheritance is a method where a derived class is derived from another derived class.

#include <iostream.h>
class mm
  {
    protected:
      int rollno;
    public:
      void get_num(int a)
        { rollno = a; }
      void put_num()
        { cout << "Roll Number Is:\n"<< rollno << "\n"; }
  };
class marks : public mm
  {
    protected:
      int sub1;
      int sub2;
    public:
      void get_marks(int x,int y)
        {
           sub1 = x;
           sub2 = y;
        }
      void put_marks(void)
        {
          cout << "Subject 1:" << sub1 << "\n";
          cout << "Subject 2:" << sub2 << "\n";
        }
   };
class res : public marks
   {
     protected: 
       float tot;
     public:
       void disp(void)
          {
            tot = sub1+sub2;
            put_num();
            put_marks();
            cout << "Total:"<< tot;
          }
   };
int main()
   {
     res std1;
     std1.get_num(5);
     std1.get_marks(10,20);
     std1.disp();
     return 0;
  }

Hybrid Inheritance Example: Hybrid Inheritance is a method where one or more types of inheritance are combined together and used.
#include <iostream.h>
class mm
  {
    protected:
      int rollno;
    public:
      void get_num(int a)
       { rollno = a; }
      void put_num()
       { cout << "Roll Number Is:"<< rollno << "\n"; }
  };
class marks : public mm
  {
   protected:
     int sub1;
     int sub2;
   public:
     void get_marks(int x,int y)
       {
         sub1 = x;
         sub2 = y;
       }
     void put_marks(void)
       {
          cout << "Subject 1:" << sub1 << "\n";
          cout << "Subject 2:" << sub2 << "\n";
      }
  };

class extra 
  {
    protected:
      float e;
    public:
    void get_extra(float s)
      {e=s;}
    void put_extra(void)
      { cout << "Extra Score::" << e << "\n";}
  };

class res : public marks, public extra{
   protected: 
     float tot;
   public:
     void disp(void)
       {
         tot = sub1+sub2+e; 
         put_num();
         put_marks();
         put_extra();
         cout << "Total:"<< tot;
       }
 };

int main()
 {
   res std1;
   std1.get_num(10);
   std1.get_marks(10,20);
   std1.get_extra(33.12);
   std1.disp();
   return 0;
 }
When a base class is privately inherited by a derived class, public members of the
base class become private members of the derived class and therefore the public
member of the base class can only be accessed by the member functions of the derived class. They are inaccessible to the object of the derived class. 
A public member of a class can be accessed by its own objects using dot operator.
The result is that no member of the base class is accessible to the object of the derived class.

Visibility of Inherited members:



Wednesday, February 24, 2010

Object Oriented Systems UNIT 1 (NOTES)

OO Analysis and Design-
OO Analysis - examines requirements from the perspective of the classes and objects found in the vocabulary of the problem domain. In other words, the world (of the system) is modelled in terms of objects and classes.
OO Design - OO decomposition and a notation for depicting models of the system under development. Structures are developed whereby sets of objects collaborate to provide the behaviours that satisfy the requirements of the problem.

Object Oriented Analysis-

  • Analyze the domain problem
  • Describe the process systems
  • Identify the objects
  • Specify attributes
  • Defining operations
  • Inter-object Communication
Identifying Object-

• Objects can be:
  • External Entity (e.g., other systems, devices, people) that produce or consume information to be used by system
  • Things (e.g., reports, displays, letters, signals) that are part of information domain for the problem
  • Places (e.g., book’s room) that establish the context of the problem and the overall function of the system.
  • Organizational units (e.g., division, group, team, department) that are relevant to an application,
  • Transaction (e.g., loan, take course, buy, order).
Objects –
  •  Object is an abstraction of something in a problem domain, reflecting the capabilities of the system to  keep information about it, interact with it, or both.
  •  Objects are entities in a software system which represents instances of real-world and system entities.


Object Class-
         Class is a description of a set of objects that share the same attributes, operations, methods, relationship and semantics.
         Object classes are templates for objects. They may be used to create objects.
         An object represents a particular instance of a class.

Term of objects-

         Attribute: data items that define object. An attributes is a data value held by the object in a class. Example- Color, weight and model year are attributes of Car objects.
         Operation: function in a class that combines to form behavior of class. Each operation has a target object as an implicit argument.
         Methods: the actual implementation of procedure (the body of code that is executed in response to a request from other objects in the system).




Encapsulation and Data Hiding-
         Packaging related data and operations together is called encapsulation.
         Data hiding: hides the internal data from external by methods (interface).

Encapsulation-

l      private attributes and methods are encapsulated within the class, they cannot be seen by clients of the class
l      public methods define the interface that the class provides to its clients



Object communication-
         Objects communicate with each other by sending messages
        a message is a method call from a message-sending object to a message-receiving object
        a message consists of
         an object reference which indicates the message receiver
         a method name (corresponding to a method of the receiver), and
         parameters (corresponding to the arguments of the calling method)
        a message-receiving object is a server to a message-sending object, and the message-sending object is a client of the server






Message Passing

Inheritance-
         Object classes may inherit attributes and services from other object classes.
         Inheritance represents the generalization of a class.

A generalisation hierarchy- Generalization and inheritance are powerful abstractions for sharing similarities among classes while preserving their differences. Generalization is the relationship between a class and one or more refined version of it. The class being refined is called its super class and each refined version is called a sub class. The notation for generalization is a triangle connecting a super class to its sub class.









Multiple inheritance-

         Rather than inheriting the attributes and services from a single parent class, a system which supports multiple inheritance allows object classes to inherit from several super-classes
         Can lead to semantic conflicts where attributes/services with the same name in different super-classes have different semantics
         Makes class hierarchy reorganisation more complex



Advantages of inheritance-

         It is an abstraction mechanism which may be used to classify entities
         It is a reuse mechanism at both the design and the programming level
         The inheritance graph is a source of organisational knowledge about domains and systems

Problems with inheritance-
         Object classes are not self-contained. they cannot be understood without reference to their super-classes
         Designers have a tendency to reuse the inheritance graph created during
         analysis. Can lead to significant inefficiency
         The inheritance graphs of analysis, design and implementation have different functions and should be separately maintained


Link:
·         A link is a physical or conceptual connection between object instances
·         A link is an instance of an association.
Objects Association-
         Modeling an association between two classes means that there is some sort of relationship between objects of each class that may be connected.
         An association describes a group of links with common structure and common semantics.
         Although associations are modeled as bidirectional they do not have to be implemented in both directions.
         Association may be binary, ternary or higher order.


Object aggregation-
         Aggregation model shows how classes which are collections are composed of other classes Similar to the part-of relationship in semantic data models.
         Aggregation is a strong form of association in which an aggregate object is made of components.
         A single aggregate object may have several parts; each part-whole relationship is treated as a separate aggregation in order to emphasize the similarity to association.


Polymorphism-
         The ability of different objects to perform the appropriate method in response to the same message is known as polymorphism.
         the selection of the appropriate method depends on the class used to create the object



Candidate Keys: A candidate key is a minimal set of attributes that uniquely identifies an object or link by minimal, we mean that you can not be discard an attribute from the candidate key and still all objects and link. A class or association may have one or more candidate keys, each of which may have different combinations and attributes. The object id is always a candidate key for a class. One or more combinations of related objects are candidate key for associations.


Example of candidate objects-

Just a Line management wishes to increase security, both in their building and on site, without antagonizing their employees. They would also like to prevent people who are not part of the company from using the Just a Line car park.
It has been decide to issue identity cards to all employees, which they are expected to wear while on the Just a Line site. The cards records the name, department and number of the member of staff, and permit access to the Just a Line  car park.
A barrier and a card reader are placed at the entrance to the car park. The driver of an approaching car insert his or her numbered card in the card reader, which then checks that the card number is known to the Just a Line system. If the card is recognized, the reader sends a signal to raise the barrier and the car is able to enter the car park.
At the exit, there is also a barrier, which is raised when a car wishes to leave the car park.
When there are no spaces in the car park a sign at the entrance display “Full” and is only switched off when a car leaves.
Special visitor’s cards, which record a number and the current date, also permit access to the car park. Visitor’s cards may be sent out in advance, or collected from reception. All visitor’s cards must be returned to reception when the visitor leaves Just a Line.



Candidate objects:
Just a Line              management                          security                              building
Site                         employee                                people                               company
car park                  card                                        name                                  department
number                   member of staff                     access                                barrier
card reader             entrance                                  driver                                car
system                   signal                                       exit                                    space
sign                        visitor                                     reception

Candidate objects’ rejection-

         duplicates: if two or more objects are simply different names for the same thing.
         irrelevant: objects which exists in the problem domain, but which are not intended.
         vague: when considering words carefully it sometimes becomes clear that they do not have a price meaning and cannot be the basis of a useful in the system.
         general: the meaning is too broad.
         attributes: as the attribute of objects.
         associations: actually represents the relationships between objects.
         roles: sometimes objects referred to by the role they play in a particular part of the system.


Rejected Candidate objects





Rest Objects-
Car park                                   Staff Card                       Visitor’s card
Employee                                 Entrance                          exit                        
card reader                               barrier                              Full sign
space                                        sensor                              car


Object Relationship-






Multiplicity-
  • Multiplicity specifies how many instances of one class may relate to single instances of one class may relate to single instances of associated classes.
  • Multiplicity contains the number of related classes.
  • Multiplicity depends on assumptions and how you define the boundaries of a problem.

Role Name-
  • A role is one end of association.
  • A binary association has two roles, each of which may have a role name.
  • A role name is a name that uniquely identifies one end of association 





Metadata- Metadata is data that describe other data. For example, the definition of a class is metadata. Many real world applications have metadata, such as parts, catalogs, blue-prints and dictionaries.

Constraints- Constraints are functional relationship between entities of an object model. The term entity includes objects, classes, attributes, links and association. A constraint restricts the values that entries can assume. Examples include: No employee’s salary can exceed the salary of the employee’s boss.





Followers