0% found this document useful (0 votes)
5 views

Unit III File Handling , Classes_Part9

The document outlines the structure and functionality of student registration and login forms, including the necessary data fields and methods for handling these forms in Python. It also discusses concepts such as instance variables, static variables, access modifiers, abstraction, and polymorphism in object-oriented programming. Additionally, it provides examples of class definitions and method implementations related to these concepts.

Uploaded by

Saraswathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Unit III File Handling , Classes_Part9

The document outlines the structure and functionality of student registration and login forms, including the necessary data fields and methods for handling these forms in Python. It also discusses concepts such as instance variables, static variables, access modifiers, abstraction, and polymorphism in object-oriented programming. Additionally, it provides examples of class definitions and method implementations related to these concepts.

Uploaded by

Saraswathi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

 Consider I have 2 forms :

 Student register form


 Student login form

 Student register form:


 Student name, age, class, branch, year, address, city,
state, phone number, username, password
 Student login form:
 Student username, password
Class StudentEncap:
class StudentRegisterForm:
__name=“”
__age=0 pass
__username=“” class StudentLoginForm:
__password=“” pass

def setNAME(self,name):
self.__name=name Event: Btn_Save()
def getNAME(self):
return(self.__name)
def setAGE(self,age): objStudent= StudentEncap()
self.__age=age objStudent.setName(txtName.text())
def getAGE(self): objStudent.setAge(txtAge.text())
return(self.__age)
def setUSERNAME(self,username): InsertToDatabase(objStudent)
self.__username=username
********************************************
def getUSERNAME(self):
return(self.__username) Event: Btn_View()
def setPASSWORD(self,password):
self.__password=password objStudent = StudentEncap()
def getPASSWORD(self):
return(self.__password) objStudent=GetDetailsFromDatabase()
txtName.text=s1.getName()
txtAge.text=s1.getAge()
Variables & Methods in python
 Instance variables
 Static variables // Class level var : Value is same for all
objects
 Local variables
class Student:
def __init__(self,rno,name):
self.rno=rno
S1=Student(72,”John”)
self.name=name S1.display()
Student.uni=“MLR” S2.Student(73,”Smith”)
def display(self):
print(self.ro,self.name)
S2.display()
class Student:
uni=“Mlore”
def __init__(self,rno,name): @staticmethod
self.rno=rno def show(): No self paramtere
self.name=name Student.uni=“MLOR”
def display(self): print(Student.uni)
print(self.ro,self.name)
print(Student.uni) S1=Student(72,”John”)
S1.display()
S2.Student(73,”Smith”)
S2.display()
Student.show()
# program to illustrate access modifiers of a class # public member function
def displayPublicMembers(self):

# super class
# accessing public data members
class Super:
print("Public Data Member:", self.var1)

# public data member # protected member function


var1 = None def _displayProtectedMembers(self):

# protected data member # accessing protected data members


print("Protected Data Member:", self._var2)
_var2 = None
# private member function
# private data member def __displayPrivateMembers(self):
__var3 = None
# accessing private data members
# constructor print("Private Data Member:", self.__var3)
def __init__(self, var1, var2, var3):
# public member function
self.var1 = var1
def accessPrivateMembers(self):
self._var2 = var2
self.__var3 = var3 # accessing private member function
self.__displayPrivateMembers()
# derived class # calling public member functions of the class
class Sub(Super): obj.displayPublicMembers()
obj.accessProtectedMembers()
obj.accessPrivateMembers()
# constructor print()
def __init__(self, var1, var2, var3):
Super.__init__(self, var1, var2, var3) # Can also be accessed using
obj._displayProtectedMembers()
obj._Super__displayPrivateMembers()
# public member function
print()
def accessProtectedMembers(self):
self._displayProtectedMembers()# Object can access protected member
print("Object is accessing protected member:", obj._var2)
# creating objects of the derived class print("Object is accessing private member:", obj._Super__var3
obj = Sub("Geeks", 4, "Geeks!")
# object can not access private member, so it will generate
Attribute error
# print(obj.__var3)
Abstraction:
 Abstract Class is a collection of abstract methods
 Abstract class cannot be instantiated (Cannot create an object)
 If there is inherited, only we can implement abstract class

 Abstract Method contains only declaration (No definition)


 @abstractmethod decorator

from abc import ABC, abstractmethod


Class AbstractDemo1(ABC):
@abstractmethod #decorator
def display(self):
pass

class AbstractDemo2(AbstractDemo1):
def display(Self):
print(“AD@ display”)

Obj=AbsractDemo2()
Obj.display()
from abc import ABC, abstractmethod
Class AbstractDemo1(ABC): #abstract class
@abstractmethod #decorator
def display(self):
pass

@abstractmethod #decorator
def show(self):
pass

class AbstractDemo2(AbstractDemo1): #abstract class Its not having all methods of abstract class
def display(Self):
print(“AD2 display”)
class AbstractDemo3(AbstractDemo1):
def display(Self):
print(“AD3 display”)
def Show(Self):
print(“AD3 display”)

Obj=AbsractDemo3()
Obj.display()
Obj.show()
Polymorphism:
 Operator Overloading:
 Using same operator for different purpose
 We can provide extra meaning to existing operator
without changing its previous meaning
 +  add 2 numbers; concatenate 2 strings;
 cannot add 2 objects, but can be done using operator
overloading
 Method Overloading
 Method Overriding

You might also like