Showing posts with label Python GCE OL AL Tamil Sinhala English Medium Classes. Show all posts
Showing posts with label Python GCE OL AL Tamil Sinhala English Medium Classes. Show all posts

Friday, August 22, 2025

Introduction to Object Orientation Encapsulation Inheritance Polymorphism Abstraction Classes & Objects Python

๐Ÿ“˜ Part 1: Introduction to Object Orientation

  • Object Orientation = A way of designing programs around objects (real-world things).

  • Each object has:

    • Properties (attributes/data) → e.g., a Car has color, model

    • Methods (functions/behavior) → e.g., a Car can start(), stop()

Why use Object Orientation?

  • Models the real world better

  • Easy to reuse and extend code

  • Easier maintenance

  • Saves development time


๐Ÿ“˜ Part 2: Main Principles of OOP

  1. Encapsulation → hiding details

    • Example: You just call tv.turnOn(), you don’t care how it works inside.

  2. Inheritance → child class gets features of parent class

    • Example: Dog and Cat inherit from Animal.

  3. Polymorphism → same function, different behavior

    • Example: draw() works differently for Circle and Square.

  4. Abstraction → show only important things, hide details

    • Example: A car’s steering wheel hides the complex engine mechanism.

  5. Classes & Objects

    • Class = blueprint (like a recipe)

    • Object = actual thing created from blueprint (like a cake baked from recipe)


๐Ÿ“˜ Part 3: Python Basics Refresher

✅ Data Structures

Structure Written With Ordered? Changeable? Allows Duplicates? Example
Tuple () Yes ❌ No ✅ Yes (1, 2, "Hi")
List [] Yes ✅ Yes ✅ Yes [1,2,2,3]
Set {} No ✅ Yes ❌ No {1,2,3}
Dictionary {key:val} Yes ✅ Yes Keys ❌ dupes, Values ✅ {"A":10, "B":20}

✅ Variables

  • Must start with a letter or _

  • Cannot start with number

  • Case-sensitive (Age ≠ age)

  • Use meaningful names (student_age ✔ vs x ✘)


✅ Operators

  • Arithmetic: + - * / % ** //

  • Comparison: == != > < >= <=

  • Logical: and, or, not

  • Assignment: =, +=, -=

  • Membership: in, not in

  • Identity: is, is not


✅ Indentation in Python

  • Python uses spaces instead of { }.

  • Example:

if age >= 18:
    print("Adult")
else:
    print("Child")

๐Ÿ“˜ Part 4: Control Flow

  1. Sequence → run line by line

  2. Selection (if/else) → decision-making

  3. Repetition (loops) → repeat tasks

    • for loop → repeat fixed times

    • while loop → repeat until condition false

    • break → exit loop early

    • continue → skip one loop step


๐Ÿ“˜ Part 5: Functions

  • A function = block of code that does something specific.

def greet(name):
    return "Hello " + name

print(greet("Faaz"))
  • Functions improve reusability and organization.


๐Ÿ“˜ Part 6: Sorting & Searching

  • Bubble Sort → repeatedly swap until sorted (slow for big data).

  • Selection Sort → pick smallest, put in front.

  • Insertion Sort → place each new item in correct place.

  • Merge & Quick Sort → faster, used in real life.


๐Ÿ“˜ Part 7: Advanced Math

  • Factorial5! = 5×4×3×2×1 = 120

  • Permutations (order matters) → number of ways to arrange items

  • Combinations (order doesn’t matter) → number of ways to choose items


๐Ÿ“˜ Part 8: OOP in Python

class Dog:
    def __init__(self, name):  # constructor
        self.name = name       # attribute

    def bark(self):            # method
        print(self.name + " says Woof!")

dog1 = Dog("Buddy")  # create object
dog1.bark()          # Output: Buddy says Woof!
  • self → refers to the object itself (must always be used inside class).

  • Method vs Function

    • Function → independent

    • Method → belongs to a class/object


๐Ÿ“˜ Part 9: Flowcharts & Problem Solving

  • Flowcharts help visualize logic.

  • Example: A game where user inputs a number, computer generates random number → compare → check win/loss.



๐Ÿ”น Cohesion (togetherness inside a class/module)

  • Meaning: How strongly related the functions inside one class are.

  • High Cohesion = everything in the class is focused on one clear job.

  • Low Cohesion = class does many unrelated jobs → confusing & hard to maintain.

✅ Example:

# High Cohesion (Payment related only)
class PaymentProcessor:
    def validate_payment(self): pass
    def process_payment(self): pass
    def send_receipt(self): pass

This class only handles payment-related workhigh cohesion.

# Low Cohesion (Mixing many jobs)
class Utility:
    def send_email(self): pass
    def calculate_salary(self): pass
    def draw_graph(self): pass

Here, one class is trying to do too many different thingslow cohesion.


๐Ÿ”น Coupling (connections between classes/modules)

  • Meaning: How much one class depends on another class.

  • Tightly Coupled = classes know too much about each other → hard to change one without breaking the other.

  • Loosely Coupled = classes depend only on essential information → flexible and easy to maintain.

✅ Example:

# Loose Coupling (better)
class PaymentProcessor:
    def process(self, payment_method):
        payment_method.pay()

class CreditCard:
    def pay(self): print("Paying with Credit Card")

class PayPal:
    def pay(self): print("Paying with PayPal")

processor = PaymentProcessor()
processor.process(PayPal())  # Can easily swap methods

Here, PaymentProcessor only needs to know that payment_method has a pay() function.
It doesn’t care how PayPal or CreditCard works inside → loosely coupled.

# Tight Coupling (bad)
class PaymentProcessor:
    def pay_with_creditcard(self): pass
    def pay_with_paypal(self): pass

If you add a new method (e.g., Bitcoin), you must modify the class.
This makes the system hard to extend → tightly coupled.


๐Ÿ”น Rule of Thumb

๐Ÿ‘‰ Good software should be Highly Cohesive + Loosely Coupled:

  • Each class does one job well (high cohesion).

  • Classes know only what they must about each other (loose coupling).

That’s how professional software is easier to read, test, reuse, and maintain.




๐Ÿ”น What is Abstraction?

Abstraction = show only important details and hide the unnecessary ones.
๐Ÿ‘‰ Example: When you drive a car, you just use the steering wheel & pedals.
You don’t see the engine’s wires or fuel injection system — that’s hidden.


๐Ÿ”น Types of Abstraction in OOP

1. Classification Abstraction

  • Meaning: Grouping similar objects into classes.

  • Analogy: Labrador, Poodle, Bulldog → all grouped as Dog.

  • Focus: Looks at similarities.

class Dog:
    def __init__(self, breed):
        self.breed = breed

dog1 = Dog("Labrador")
dog2 = Dog("Poodle")

Here, Dog is a general class for all breeds.


2. Generalization Abstraction

  • Meaning: Creating parent-child relationships (inheritance).

  • Analogy: "Mammal" is a general class → Dog, Cat, Horse are children.

  • Focus: Top-down → from general → specific.

class Animal:   # Parent
    def breathe(self): print("Breathing")

class Dog(Animal):   # Child
    def bark(self): print("Woof!")

d = Dog()
d.breathe()  # Inherited
d.bark()

Here, Dog inherits general features of Animal.


3. Aggregation Abstraction (weak “has-a” relation)

  • Meaning: One object contains another, but parts can live independently.

  • Analogy: A Car has a Radio. The Radio can exist without the Car.

class Radio:
    def play(self): print("Playing music")

class Car:
    def __init__(self, radio):
        self.radio = radio   # "has-a" relation

my_radio = Radio()
my_car = Car(my_radio)
my_car.radio.play()

4. Composition Abstraction (strong “part-of” relation)

  • Meaning: Stronger form of aggregation → parts cannot exist independently.

  • Analogy: A House has Rooms. Rooms do not exist outside the house.

class Room:
    def __init__(self, name):
        self.name = name

class House:
    def __init__(self):
        self.rooms = [Room("Living"), Room("Bedroom")]

h = House()
for r in h.rooms:
    print(r.name)

Here, Room objects exist only because the House exists.


5. Behavioral Abstraction

  • Meaning: Hiding implementation details of methods, only showing what they do.

  • Analogy: You click “Print” → you don’t know if it’s laser/inkjet, but you get output.

  • Focus: Method signatures, not how they work inside.

class Printer:
    def print_document(self):   # behavior is abstract
        raise NotImplementedError("Subclasses must implement")

class LaserPrinter(Printer):
    def print_document(self):
        print("Printing with laser...")

class InkjetPrinter(Printer):
    def print_document(self):
        print("Printing with inkjet...")

p = InkjetPrinter()
p.print_document()

Here, print_document() hides details, but each printer implements it differently.


๐Ÿ”น Summary

Type Focus Example
Classification Grouping similar objects Dogs → Dog class
Generalization Parent-child hierarchy Animal → Dog, Cat
Aggregation Weak "has-a" Car has a Radio
Composition Strong "part-of" House has Rooms
Behavioral Hide method details Printer with different implementations

.


๐Ÿ”น Classification

  • Meaning: Grouping similar objects into classes based on common properties.

  • Approach: Bottom-Up → start from specific objects → group them.

  • Question it answers: “What category does this object belong to?”

✅ Example:

  • Labrador, Poodle, Bulldog → all grouped as Dog.

  • Cat, Tiger, Lion → all grouped as Cat family.

# Classification Example
class Dog:
    def __init__(self, breed):
        self.breed = breed

dog1 = Dog("Labrador")
dog2 = Dog("Poodle")
print(dog1.breed)   # Labrador

Here, classification means: we group similar objects → all are Dogs.


๐Ÿ”น Generalization

  • Meaning: Create hierarchies where specific classes inherit from general ones.

  • Approach: Top-Down → start from general concept → create specialized ones.

  • Question it answers: “What is the more general concept that covers this?”

✅ Example:

  • “Dog”, “Cat”, “Horse” → all are generalized as Animal.

# Generalization Example
class Animal:  # General (parent)
    def breathe(self): print("Breathing")

class Dog(Animal):  # Specific (child)
    def bark(self): print("Woof!")

class Cat(Animal):  # Specific (child)
    def meow(self): print("Meow!")

d = Dog()
d.breathe()   # Inherited from Animal
d.bark()

Here, generalization means: we create a general Animal class → and let Dog & Cat inherit from it.


๐Ÿ”น Key Differences (Side-by-Side)

Feature Classification Generalization
Definition Grouping similar objects into categories Building parent-child relationships
Direction Bottom-Up (from specific → category) Top-Down (from general → specialized)
Focus Similarities among objects Hierarchies & inheritance
Example Labrador + Poodle + Bulldog = Dog class Dog, Cat, Horse → inherit from Animal class
Question “What category is this object in?” “What general concept does this belong to?”

๐Ÿ”น Real-Life Analogy

  • Classification:

    • You look at fruits → Apple, Banana, Orange → group them as Fruits.

  • Generalization:

    • You start with “Plant” → then generalize into “Fruit” and “Vegetable”.


In short:

  • Classification organizes objects into groups.

  • Generalization creates parent-child hierarchies among those groups.


๐Ÿƒ Flashcards for OOP with Python 


๐Ÿ”น Beginner (Basics)

Q1: What is Object Orientation?
A1: A way of designing programs around objects (real-world entities) that have attributes (data) and methods (behavior).

Q2: What is a Class?
A2: A blueprint/template for creating objects.

Q3: What is an Object?
A3: An instance of a class (real thing created from the blueprint).

Q4: What are the 4 main principles of OOP?
A4: Encapsulation, Inheritance, Polymorphism, Abstraction.

Q5: What is the difference between Attributes and Methods?
A5: Attributes = variables (data of object). Methods = functions (behavior of object).


๐Ÿ”น Encapsulation & Abstraction

Q6: What is Encapsulation?
A6: Hiding internal details of a class and controlling access using getters & setters.

Q7: Example of Encapsulation in Python?
A7:

class Bank:
    def __init__(self, balance):
        self.__balance = balance
    def get_balance(self):
        return self.__balance

Q8: What is Abstraction?
A8: Showing only necessary features, hiding the implementation details.

Q9: Types of Abstraction?
A9: Classification, Generalization, Aggregation, Composition, Behavioral.

Q10: Example of Abstraction in real life?
A10: Driving a car → you use the steering wheel (interface), but don’t see engine details.


๐Ÿ”น Inheritance & Polymorphism

Q11: What is Inheritance?
A11: When a class (child) inherits attributes & methods from another class (parent).

Q12: What is Polymorphism?
A12: Same method name, different behavior depending on object.

Q13: Python Example of Polymorphism?
A13:

class Dog:
    def speak(self): print("Woof!")
class Cat:
    def speak(self): print("Meow!")
for animal in [Dog(), Cat()]:
    animal.speak()

๐Ÿ”น Cohesion & Coupling

Q14: What is High Cohesion?
A14: A class does only one job well (focused).

Q15: What is Low Coupling?
A15: Classes are independent and interact only through simple interfaces.

Q16: Ideal design principle?
A16: High Cohesion + Low Coupling → modular, reusable code.


๐Ÿ”น Python Basics from PDF

Q17: List vs Tuple vs Set vs Dictionary?
A17:

  • List → ordered, mutable, allows duplicates

  • Tuple → ordered, immutable

  • Set → unordered, unique values only

  • Dictionary → key-value pairs

Q18: What is Indentation in Python?
A18: Spaces at the start of a line that define blocks of code (instead of {}).

Q19: What does break and continue do in loops?
A19: break exits loop, continue skips current iteration.


๐Ÿ”น Control Flow

Q20: Difference between Sequence, Selection, and Repetition?
A20:

  • Sequence → step-by-step execution

  • Selection → decision-making (if/else)

  • Repetition → looping (for, while)

Q21: Deterministic vs Non-Deterministic Loops?
A21:

  • Deterministic → fixed iterations (e.g., for i in range(5))

  • Non-Deterministic → unknown iterations (e.g., while user_input != "stop")


๐Ÿ”น Functions & Recursion

Q22: What is a Function?
A22: A reusable block of code with name, parameters, and optional return value.

Q23: Difference between Function and Method?
A23:

  • Function = standalone block

  • Method = belongs to a class/object

Q24: What is Recursion?
A24: A function calling itself until a base case is reached.

Q25: Recursion vs Iteration?
A25:

  • Recursion → uses call stack, may risk stack overflow

  • Iteration → uses loops, more memory efficient


๐Ÿ”น Algorithms

Q26: What is Bubble Sort?
A26: Repeatedly swap adjacent elements if out of order.

Q27: What is Selection Sort?
A27: Repeatedly find the minimum element and place it in order.

Q28: What is Insertion Sort?
A28: Insert each element into the correct position in sorted part.

Q29: What is Merge Sort?
A29: Divide & conquer → split list, sort halves, merge results.

Q30: What is Quick Sort?
A30: Choose a pivot, partition list, sort sublists recursively.


๐Ÿ”น Math & Probability

Q31: What is Factorial?
A31: n! = n × (n-1) × ... × 1

Q32: What is a Permutation?
A32: Selection where order mattersnPk = n! / (n-k)!

Q33: What is a Combination?
A33: Selection where order does NOT matternCk = n! / (k!(n-k)!)


๐Ÿ”น Advanced OOP in Python

Q34: What is self in Python classes?
A34: Refers to the current object instance (needed for attributes & methods).

Q35: Why use __ (double underscore) before variable names?
A35: To make them private → accessed only through getters/setters.

Q36: What is the difference between Public, Protected, and Private attributes in Python?
A36:

  • Public → normal (name) → accessible anywhere

  • Protected → _name → “internal use only” (by convention)

  • Private → __name → hidden, only accessible inside class


๐Ÿ”น Flowcharts & Problem Solving

Q37: Why use Flowcharts for algorithms?
A37: Visual clarity, easier debugging, error detection, and communication.

Q38: Example: Game logic flashcard
Q38A: User inputs number → computer generates random → compare → if 2+ matches in 3 tries → Win.



๐Ÿ’ฅ Whatsapp https://wa.link/b72px4

๐Ÿ’ฅ YouTube https://www.youtube.com/channel/UCJojbxGV0sfU1QPWhRxx4-A

๐Ÿ’ฅ Blog https://localedxcelcambridgeictcomputerclass.blogspot.com/

๐Ÿ’ฅ WordPress https://computerclassinsrilanka.wordpress.com

๐Ÿ’ฅ Facebook https://web.facebook.com/itclasssrilanka

๐Ÿ’ฅ Wix https://itclasssl.wixsite.com/icttraining

๐Ÿ’ฅ Web https://itclasssl.github.io/eTeacher/

๐Ÿ’ฅ Medium https://medium.com/@itclasssl

๐Ÿ’ฅ Quora https://www.quora.com/profile/BIT-UCSC-UoM-Final-Year-Student-Project-Guide

๐Ÿ’ฅ mystrikingly https://bit-ucsc-uom-final-year-project-ideas-help-guide-php-class.mystrikingly.com/

๐Ÿ’ฅ https://elakiri.com/threads/bit-ucsc-uom-php-mysql-project-guidance-and-individual-classes-in-colombo.1627048/

๐Ÿ’ฅ https://bitbscucscuomfinalprojectclasslk.weebly.com/

๐Ÿ’ฅ https://www.tiktok.com/@onlinelearningitclassso1

๐Ÿ’ฅ https://payhip.com/eTeacherAmithafz/

๐Ÿ’ฅ https://discord.gg/cPWAANKt

๐Ÿ’ฅ https://6789f6ca695da.site123.me/blog

๐Ÿ’ฅ https://eteacher-49046330.hubspotpagebuilder.com/join-the-best-ict-software-project-classes-in-sri-lanka

๐Ÿ’ฅ https://www.tumblr.com/blog/computercoursesincolombo-blog

๐Ÿ’ฅSubscribe on LinkedIn https://www.linkedin.com/build-relation/newsletter-follow?entityUrn=7072056309516304384

๐Ÿ’ฅhttps://www.scribd.com/user/682883198/Online-Learning-IT-Class-Software-Dev



---


๐Ÿš€ Join the Best BIT Software Project Classes in Sri Lanka! ๐ŸŽ“  


Are you a BIT student struggling with your final year project or looking for expert guidance to ace your UCSC final year project? ๐Ÿ’ก We've got you covered!  


✅ What We Offer:  

- Personalized project consultations  

- Step-by-step project development guidance  

- Expert coding and programming assistance (PHP, Python, Java, etc.)  

- Viva preparation and documentation support  

- Help with selecting winning project ideas  


๐Ÿ“… Class Schedules:  

- Weekend Batches: Flexible timings for working students  

- Online & In-Person Options  


๐Ÿ† Why Choose Us?  

- Proven track record of guiding top BIT projects  

- Hands-on experience with industry experts  

- Affordable rates tailored for students  


๐Ÿ”— Enroll Now: Secure your spot today and take the first step toward project success!  


๐Ÿ“ž Contact us: https://web.facebook.com/itclasssrilanka  

๐Ÿ“ Location: Online  

๐ŸŒ Visit us online: https://localedxcelcambridgeictcomputerclass.blogspot.com/


✨ Don't wait until the last minute! Start your BIT final year project with confidence and guidance from the best in the industry. Let's make your project a success story!  


---

Individual attention to all students 

๐ŸŽ“ Final Year IT & Computer Science Students! ๐Ÿš€

Get Expert Guidance for Your Degree Projects & Reports!


๐Ÿ“ Colombo | Moratuwa | UoM | Colombo Uni | BIT | BIT Degree | SLIIT | BSc


๐Ÿ’ก We Specialize In:

✅ Project Proposal Writing (University-Ready)

✅ Interim Report Assistance

✅ Final Dissertation / Use Case Document Support

✅ Test Manual & Installation Guides

✅ Complete Final-Year Project System (Fully Working)

✅ Test Document Preparation

✅ Computer Studies / BIT / Software Engineering / IT / VLE Courses


๐Ÿ‘จ‍๐Ÿซ Supervision by Experienced Software Developers & University Project Guides

๐Ÿ“˜ Covers: Java, Python, PHP, MySQL, AI, Web & Mobile Development, Machine Learning


๐Ÿ“ž Contact Now to Book Your Slot – Limited Project Guidance Available!


๐Ÿš€ **LEARN COMPUTER SCIENCE & TECH SKILLS FROM ZERO TO PRO!** ๐ŸŽ“๐Ÿ’ป

✨ *Future-Proof Your Career with Our Practical Courses!*


๐Ÿ“š **Courses We Offer:**


๐ŸŽ“ **ICT for School Leavers (Post O/L or A/L)**

✅ Intro to IT & Careers in ICT

✅ MS Office (Word, Excel, PowerPoint, Access)

✅ Email, Conferencing & Digital Communication

✅ Databases & Queries

✅ Intro to Python Programming

✅ Basic Graphic Design & Photo Editing

✅ Project Work: Resume, Reports, Presentations


๐Ÿ’ป Web Development (Beginner → Intermediate)

๐ŸŒ Web Basics: HTML5, CSS3, Responsive Design

⚡ JavaScript, Forms & Validation

๐Ÿ–ฅ️ Backend with PHP/Node.js + MySQL

๐ŸŒŸ Hosting, Domain Setup, GitHub Deployment

๐ŸŽจ Optional: WordPress, Figma, Canva


๐Ÿ“ฑ **Social & Digital Media Marketing**

๐Ÿ“ˆ SEO, Google Ads & Content Marketing

๐Ÿ“ฒ Facebook, Instagram, TikTok & YouTube Marketing

๐ŸŽฏ Ads Manager, Email Marketing, Analytics

๐Ÿ› ️ Capstone Project: Create a Real Campaign!


๐Ÿ–ฅ️ **Computer Programming (Beginner → Intermediate)**

๐Ÿ Python/Scratch Basics – Logic, Loops, Functions

๐Ÿ‘จ‍๐Ÿ’ป Object-Oriented Programming

๐ŸŽฎ Mini Projects: Games, GUIs, Databases


๐Ÿค– **Artificial Intelligence (AI) – Beginner Level**

๐Ÿ” AI Basics: History, Applications, AI vs ML

๐Ÿ“Š Machine Learning with Python & scikit-learn

๐Ÿง  Projects: Image Recognition, Chatbots, Voice Assistant

⚖️ AI Ethics, Jobs & Future Trends


๐Ÿ”ฅ **WHY JOIN US?**

✅ Short-term, practical & career-focused training

✅ Hands-on projects & real-world applications

✅ Ideal for students, job-seekers & tech enthusiasts


๐Ÿ“ž **Call/WhatsApp Now:** 0777337279

๐ŸŒ **Register Today & Start Your Journey in Tech!**


✨ *Limited Seats | Certificates Provided | Learn with Experts!*


๐Ÿ’ก **Tag a Friend Who Needs This!** ๐Ÿ”–