Showing posts with label Inheritance. Show all posts
Showing posts with label Inheritance. Show all posts

Saturday, January 21, 2012

Python Note 6(Classes and Objects)

Sample Code  : General class
#define a class
class User :
 def __init__(self,name,user_id,acc_balance):
  self.Name=name
  self.User_id=user_id
  self.Acc_Balance=acc_balance
  
 def recharge(self,amount):
  self.Acc_Balance+=amount
 
 def withdraw(self,amount):
  if amount <= self.Acc_Balance :
   self.Acc_Balance-=amount
  else :
   pass #do nothing
 
 def getBalance(self): #parameter less method
  return self.Acc_Balance
  
 def __del__(self) :
  print("Destructor started!")
#end of the class
 
usr=User("Kanishka",1133,27000.00)
print("User {0} , Balance {1:5.2f}".format(usr.Name,usr.getBalance()))
usr.withdraw(2000.50) #withdrwaw money
print("User {0} , Balance {1:5.2f}".format(usr.Name,usr.getBalance()))

Monday, January 2, 2012

Inheritance Mapping

Basically there are 3 types of inheritance mapping. We may use those methods suitably.
  • SINGLE_TABLE (default)
  • JOINED
  • TABLE_PER_CLASS
Model
© kani.stack.notez 2012 | Blogger Template by Enny Law - Ngetik Dot Com - Nulis