Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Designing classes in python

I am designing a class which produces information like cpu usage,disk usage,Mem usage,...... for 3 systems,lets say data centers which has many workstations and work stations has many PCs.So the CPU usage and the other parameters are required for all the 3 levels(Datacenters, Workstations, Pcs). Please suggest is the below class design correct or how it is to be designed

EDIT

class Datacenters:
 def __init__(self,name,location,cpu,mem):
 self.name=name
 self.location=location
 self.cpu=cpu
 self.mem=mem
 def getparam(self):
 return self.name,self.location ,self.cpu,self.mem
 def getname(self):
 return self.name
class WS(Datacenters):
 def __init__(self,name,location,cpu,mem,obj):
 #datacentername = Datacenters.__init__(self) #To which data center it is associated
 obj.getname() #To which data center it is associated
 self.name=name
 self.location=location
 self.cpu=cpu
 self.mem=mem
def getparam(self,obj):
 return self.name,self.location ,self.cpu,self.mem,obj.getname()
def getpcname(self):
 return self.name
class Pcs(WS):
 def __init__(self,name,location,cpu,mem,obj):
 obj.getpcname() #To which WS it is associated
 self.name=name
 self.location=location
 self.cpu=cpu
 self.mem=mem
 def getparam(self,obj):
 return self.name,self.location ,self.cpu,self.mem,obj.getpcname()
a = Datacenters("dc1","Bl1",20,30)
print a.getparam()
b = WS("WS1","Bl1",20,30,a)
print b.getparam(a)
c = Pcs("PC1","Bl1",20,30,b)
print c.getparam(b)

Answer*

Draft saved
Draft discarded
Cancel
3
  • original class names doesn't make sense, they shouldn't be plural Commented Dec 19, 2010 at 18:27
  • @Paweł Prażak: This is true as well, I'll update. WS is also a crappy name. :) Commented Dec 19, 2010 at 18:51
  • Thanks this was elpful +1 for the explaination Commented Dec 20, 2010 at 5:21

lang-py

AltStyle によって変換されたページ (->オリジナル) /