Concept of Objects (State, Behavior & Identity) and Class Design: Identifying Classes, Attributes & Services

Concept of Objects: State, Behavior & Identity of an object

Object

Object एक real-world entity का representation होता है। यह physical entity (जैसे, Car, Person, Mobile Phone) या conceptual entity (जैसे, Bank Account, Loan, Appointment) हो सकता है। Programming में, Object एक Class का instance होता है।

सरल शब्दों में:

  • Class → Blueprint या Template
  • Object → उस blueprint से बनी हुई actual चीज़

Example: अगर Car एक Class है, तो “मेरी Red Maruti Swift” या “आपके पड़ोसी की White Hyundai Creta” Car Class के Objects हैं।
हर Object की अपनी unique characteristics होती हैं, जो उसे दूसरे Objects से अलग बनाती हैं। इन characteristics को define करने वाले तीन मुख्य pillars हैं: State, Behavior, Identity।

Three main properties of an object (मुख्य गुण)

1. State (अवस्था)

State बताती है कि Object की कौन-कौन सी properties और attributes हैं और किसी particular moment में Object किस स्थिति में है। Programming में इसे instance variables कहते हैं |
Example: Student Object 

  • name: “Rohit Sharma”
  • roll_number: 45
  • class: 12th
  • marks: 95%

State समय के साथ बदल सकती है। जैसे, अगले साल Rohit की class 12th से Graduation में बदल जाएगी।

Example: Mobile Phone 

  • brand, model, battery_level, storage_capacity
2. Behavior (व्यवहार)

Behavior बताता है कि Object क्या कर सकता है या उसके साथ क्या किया जा सकता है। Behavior को methods/functions represent करते हैं। Behavior Object की State को read या modify कर सकता है।
Example: Student Object Behavior

  • study() → पढ़ाई करना
  • play_cricket() → क्रिकेट खेलना
  • get_marks() → marks बताना
  • get_percentage() → percentage calculate करना

Relationship: Behavior, State को बदल सकता है।
Example: Bank_Account Object

  • State: balance ₹10,000
  • Behavior: withdraw(2000) → balance ₹8,000
3. Identity (पहचान)

Identity वह property है जो Object को uniquely identify करती है। दो Objects की State और Behavior same होने पर भी Identity अलग होती है।
Identity programming में unique ID या memory address से represent होती है।
Example: जुड़वाँ भाई-बहन

  • State similar हो सकती है (name, age, height)
  • Identity अलग होती है (DNA, fingerprint, student ID)

Programming Example:
car1 = Car()
car2 = Car()

  • दोनों Objects की color property 'red' हो सकती है
  • लेकिन memory में अलग जगह store होने के कारण Identity अलग रहती है

Identity से Objects को एक-दूसरे से clearly distinguish किया जा सकता है।

Example Student Object

1. State (स्थिति / Attributes): Student object की state वो जानकारी होती है जो उसके data को represent करती है।

  • Name: Riya Sharma
  • Class: 8th
  • Roll Number: 22
  • Attendance: 92%
  • Marks: {Math=88, Science=90, English=85}
  • Address: Delhi
  • Age: 13

2. Behavior (व्यवहार / Methods): Student object क्या-क्या actions perform कर सकता है, वही उसका behavior है:

  • AttendClass() → student class present करता है
  • SubmitHomework() → homework submit करता है
  • GiveExam() → exam देता है
  • ParticipateInSports() → sports activities में हिस्सा लेता है
  • UpdateAttendance() → attendance बढ़ती/घटती है
  • GetResult() → marks के आधार पर result calculate होता है

3. Identity (पहचान / Unique ID): हर student object की एक unique पहचान होती है जो कभी change नहीं होती:

  • Student ID: S10045
  • Roll Number (unique inside class): 22
  • Admission Number: ADM-2023-089

Classes: identifying classes and candidates for Classes Attributes and Services

Class

Class एक blueprint या template होती है जिसमें object के data (attributes) और उस data पर काम करने वाले functions (methods/services) define होते हैं।

Important Components

  1. Data Members (Variables / Attributes)
    • ये class की properties या data values को store करते हैं।
    • Example: name, age, color
  2. Member Functions (Methods / Behaviors)
    • ये class के actions और operations को define करते हैं।
    • Example: study(), drive(), deposit()

What is Class Identification? (Class Identification क्या होता है?)

जब हम किसी software system का design बनाते हैं, सबसे पहला Step होता है—system में कौन-कौन सी classes होंगी? यही process Class Identification कहलाता है।

Why is Class Identification Important? (Class Identification क्यों ज़रूरी है?)

1. The System Becomes Organized and Simple

  • सही classes चुनने से पूरा system clean, logical और आसानी से समझ में आने वाला बन जाता है।

2. Code Reusability Increases

  • Well-designed classes को future programs में भी reuse किया जा सकता है, जिससे development fast और efficient होता है।

3. Debugging and Maintenance Easier

  • Clear class structure होने से errors जल्दी detect होते हैं और code को maintain करना सरल हो जाता है।

4. Real-World Modeling Is Natural

  • Classes real-world entities को represent करती हैं, जिससे system users और developers दोनों के लिए intuitive लगता है।

5. Confusion Reduced in Large Projects

  • Clear responsibilities वाली classes team work को आसान बनाती हैं और बड़े software में complexity व overlap को कम करती हैं।

What are Candidates for Classes? (Candidates for Classes क्या होते हैं?)

ये वे real-world entities, concepts या software components होते हैं जिन्हें हम Class के रूप में represent कर सकते हैं।

1. Entity Classes 

ये system का core data represent करते हैं।

Examples

  • Customer
  • Product
  • Seller

Product, User, Seller → ये सभी entity classes हैं।

2. Boundary Classes

ये classes user या external system से interaction manage करती हैं।
इनमें business logic नहीं होता, बस input/output manage होता है।

Examples

  • LoginPage
  • RegistrationForm
  • PaymentScreen

Where do they appear? (कहाँ दिखती हैं?)

  • Web pages
  • Mobile app screens
  • Forms
  • Input dialogs

ये database में नहीं जातीं, सिर्फ interaction को संभालती हैं।

3. Control Classes

ये classes सारा business logic handle करती हैं, इन्हें manager, controller, या handler भी कहते हैं।

Examples

  • OrderManager
  • PaymentController
  • BookingHandler
  • TransactionProcessor

Role

  • Entity classes को coordinate करना
  • Workflow manage करना
  • Rules implement करना

How to Identify Attributes?

Attributes वो data होते हैं जो कोई class represent करती है। ये object की properties या उसकी current state को describe करते हैं।

Rules for Finding Attributes:

1. Nouns Representing Properties: अगर कोई noun किसी entity की property बताता है, वह attribute बन जाता है।

Examples:

  • Student → name, rollNo, class
  • Car → model, enginePower, color

2. State of Object: Object की appearance या state को बताने वाले elements, attributes कहलाते हैं।

Example (Paytm Wallet):

  • mobileNumber
  • balance
  • lastTransactionDate

3. Measurable Values: जिस चीज़ की measurement हो सकती है, वो attribute होगा।
Example: price, weight, age, height, date, time

4. Avoiding Wrong Attributes

  1. Action words attributes नहीं होते
    • Example: start, run, pay, login
  2. Calculated values direct attributes नहीं होती 
    • Example: totalAmount = price × qty (calculated value, not attribute)

How to Identify Services/Methods?

Services या Methods वह behaviour होते हैं जिन्हें कोई object (class का instance) perform करता है।ये बताते हैं कि object “क्या कर सकता है?” और system में कैसे act करता है। 

  • Methods class के data (attributes) पर operations करते हैं
  • System के अन्य parts के साथ interaction संभालते हैं।

1. Verb Analysis Technique

Requirement में आए हुए verbs, potential methods होते हैं।

Examples:

  • Student → giveExam()
  • Car → start()
  • Order → cancel()

2. Responsibilities 

जिस responsibility को class निभाती है → वही उसकी service बनती है।

Example:
Order → placeOrder(), cancelOrder(), updateStatus()

3. Change in State

जो भी action object की state बदलता है, वह method कहलाता है।

Examples:

  • balance बढ़ाना/घटाना → updateBalance()
  • exam देना → writeExam()

4. Real-world Behaviour

Real-world में entity जो काम करती है → वही methods बनते हैं।

Examples:

  • Doctor → prescribeMedicine()
  • Teacher → takeAttendance()
  • Train → run(), halt()
error: Content is protected !!