mardi 15 mars 2016

Using class object as a parameter to a other class function in python

I have following structure for my program-

File1.py

class A:
   index1
   def method1():
       // --do stuff--

File2.py

import File1

Class B:
   index2
   def method2(a) // Needs Object of A as a parameter
        // --do stuff--
        a.method1() // How can I guarantee that this is an object of class A

File3.py

import File1
import File2
Class Starter:
   def start():
       a = A()
       b = B()
       b.method2(a)

I have few questions-

  1. How can I ensure that parameter a in method2 is an object of class A?
  2. It might be IDE specific, but can I find out all the methods and variables that I can access in method2 on object 'a' while writing the code?
  3. Is it better to write such object oriented programs in Java rather than python?

Aucun commentaire:

Enregistrer un commentaire