Std: 12th Science
English Medium
Subject: Computer
Chapter-6
Topics:
For any computer program the core elements are: (1) data (2) functions.
For eg. in a library management software
Details about individual books in a library like book title, author name, price etc. can be stored in a database with row and column structure is considered as data.
Library software can have few functions like book_issue(), book_return(), new_member() etc…..
Name | Title | Author | Price |
You can win | You can win | Shiv Khera | 500 |
Computer languages are used to create various types of programs.
The way of programming can be divided into 2 categories:
1. Structural/Procedural languages
2. object oriented languages
In procedural languages the main focus is on writing functions or procedures which operates on data.
In object oriented languages the main focus is on object which contains data and procedure both.
Object oriented programming
Object oriented programming concepts started originating in 1960s and since mid 1980s it became the main programming paradigm.
In object oriented languages the main focus is on object which contains both data and functionality.
The popular object oriented languages are C++, Java, C#, VB.net and PHP.
A computer language is object-oriented if they support 4 specific object properties called……
What is object
Object word is taken from the real world examples….
In real world, objects are the entities of which the world is comprised.
In software we can have objects like individual books in library software, individual students and teachers in school management software.
All object have unique identity and are distinguishable from each other.
Each and every object contains one or more properties(attributes) and methods(behaviors).
Object |
Properties or Attributes |
Methods or Behaviors |
Object
Object contains various characteristics known as properties.
For eg. Every person has characteristics like name, address, city, gender etc…
Each and every property of an object contains a value known as its state.
For eg. Name = “Ram” city = “Surendranagar”
Value of a property can also be known as its state.
Objects differ from each other by their states.
Every object can have behaviors attached with them……
For eg. A book can be issued, so book_issue() is a property.
Book1 |
Book_title, author_name, price |
Display(), book_issue() |
The attributes and behavioral methods associated with an object are collectively referred to as its members or features.
Property names
Value of property
or its state
Objects should be meaningful to the application. For eg. In railway reservation application objects are trains, passengers, tickets, or station.
class
Class can be considered as a blueprint for various objects.
A class is a template for multiple objects with similar features.
It describes a group of objects with similar attributes and common behaviors.
For example we have a class named person describing common attributes and behavior.
Name City Gender Birthdate profession |
Class Person
Ram Snagar Male 8/8/2001 Teacher |
Shyam Surat Male 1/3/2000 Professor |
Jam Jamnagar Male 1/4/2000 Doctor |
object Person 1
object Person2
object Person3
Class Diagram
Std: 12th Science
English Medium
Subject: Computer
Chapter-6
Previous video Lecture
Class Diagram representation
Class Name |
Visibility attribute: data type = initial value |
Visibility operation (argument list): return type |
Class
Person |
name: string city:string gender: char = ‘M’ -birthdate: date profession: string |
setBirthdate(d:int, m:int, y:int): date changeCity (newCity:string) : string display() |
Syntax of Attribute
[<visibility>] <attribute name> [: <attribute data type> [ =<initial value>]]
Examples
Name : string
-balance : float = 0.0
Gender : char = ‘M’
Here items written in pair of square3 brackets [] are optional
Items written in pair of angle brackets <>, are compulsory.
Visibility
[<visibility>] <attribute name> [: <attribute data type> [ =<initial value>]]
Visibility can be of 4 types:
Private(-)
Protected(#)
public (+)
Package(~)
- balance : float = 0.0
Syntax of behavior
[<visibility>] <method name> (parameter list separated by comma): <return type>
Examples
setBirthdate( d:int, m:int, y:int) : date
Object Oriented programming features
Encapsulation
Data Abstraction
Messaging
abc() { …. Method code… }
…
…
abc()
Polymorphism
Method overloading
Polymorphism
Operator overloading
Std: 12th Science
English Medium
Subject: Computer
Chapter-6
Previous video Lecture
Visibility options
Encapsulation
Data Abstraction
Polymorphism
Aggregation and Composition
Person |
name: string city:string gender: char = ‘M’ -birthdate: date profession: string |
setBirthdate(d:int, m:int, y:int): date changeCity (newCity:string) : string display() |
Previously
Created
class
Person |
Nm: Name Addr: Address Gender: char = ‘M’ Birthdate: date Profession: string |
setBirthdate(d:int, m:int, y:int): date changeCity (newCity:string) : string display() |
Address |
house: string Street: string City: string State: string Pincode: int |
fullAddress(): string display() |
Name |
firstName: string middleName: string lastName: string |
fullName(): string display() |
2 new classes name and address are created first. Object of person class are composed of
Object of name and address class.
Aggregation vs. Composition
P1:person |
Nm: Name(Ram, Mohan, Joshi) Addr: Address(10, Arun Society….) Gender: char = ‘M’ -birthdate: 20-09-2003 Profession: professor |
…. |
Address |
house: 10, Arun… Street: Dalmill City: Snr State: Guj Pincode: 363001 |
… |
n1:name |
fname:Ram mName:Mohan lName:Joshi |
… |
n1:name |
fname:Shyam mName:sundar lName:Dave |
… |
P2:person |
Nm: Name(Shyam, Sundar, Dave) addr: Address(10, Arun Society….) Gender: char = ‘M’ -birthdate: 10-03-2001 Profession: professor |
…. |
Aggregation vs. Composition
Aggregation vs. Composition
P1:person |
Nm: Name(Ram, Mohan, Joshi) Addr: Address(10, Arun Society….) Gender: char = ‘M’ -birthdate: 20-09-2003 Profession: professor |
…. |
n1:name |
fname:Ram mName:Mohan lName:Joshi |
… |
Address |
house: 10, Arun… Street: Dalmill City: Snr State: Guj Pincode: 363001 |
… |
Aggregated/
subject/
part class
Aggregating/owner/
Whole class
Aggregated/
subject/
part class
Composition
Aggregation
Aggregation vs. Composition
P1:person |
Nm: Name(Ram, Mohan, Joshi) Addr: Address(10, Arun Society….) Gender: char = ‘M’ -birthdate: 20-09-2003 Profession: professor |
…. |
n1:name |
fname:Ram mName:Mohan lName:Joshi |
… |
Address |
house: 10, Arun… Street: Dalmill City: Snr State: Guj Pincode: 363001 |
… |
Aggregated/
subject/
part class
Aggregating/owner/
Whole class
Composition
Aggregation
Aggregated/
subject/
part class
Inheritance
Person |
Nm: string City: string Gender: char = ‘M’ -birthdate: 20-09-2003 Profession: string |
Display() |
Address |
house: 10, Arun… Street: Dalmill City: Snr State: Guj Pincode: 363001 |
… |
Inheritance
Person |
Nm: string City: string Gender: char = ‘M’ -birthdate: 20-09-2003 Profession: string |
Display() |
Teacher |
Subject: string |
Lecture(d:date,t:time) Display() |
Inheritance
Person |
Nm: string City: string Gender: char = ‘M’ -birthdate: 20-09-2003 Profession: string |
Display() |
Teacher |
Subject: string |
Lecture(d:date,t:time) Display() |
sub class or child class or derived class
super class or parent class or base class.