|class definition in WLST Script|
In WLST every thing is object as its base scripting language is Python suppose the same. If you create normal variable assignment uses their base objects like int, float, str etc. Each object will be created on JVM with ID, Type (object type) and value. In this post you will get to know about Object orientation for WLST scripts. The four pillars of Object orientation are supported in WLST as well.
- Encapsulation - How you hide within object
- Abstraction - How the object make interact with the world
- Inheritance -Reusing functionalities of a object
- Polymorphism - Dynamism to your methods
Why should I use OOP in WLST?
- Object are natural easy to understand and write
- Objects are more reusable
- Objects are more maintainable
- Objects can be extended
What is class in WLST?
What is 'self' do in WLST?
What is Instance?
- While you defining a class the class name must begin with Capital letter
- Explicit inheriting object type give more power to your class
- Define a method like a function. must have a first argument as self which provide access to current instance attribute values
- Better to have a DocString for each method you define in the class
# This illustrates the subclassing # Empty class with pass # usage of issubclass function class Animal(object): pass class Snake(Animal): def __init__(self): print "Ssss n a k e!!" class Python(Snake): "I like Python class" atr=0 def __init__(self): print "Busssshhhh!!!" Snake.__init__(self) self.atr+=1 def __repr__(self): return 'This is Python object' print "issubclass(Animal,object:)",issubclass(Animal,object) print "issubclass(Snake,Animal:)",issubclass(Snake,Animal) print "issubclass(Python, Snake:)",issubclass(Python, Snake) p=Python() print "Instance printing:", p print "docString:", p.__doc__ print "p is from class:", p.__class__ print "p type:",type(p) print "p id:", id(p) print "p attribute:", p.atr
Private variables in class
Exercise for Learners
- Create a class for configuring a simple domain with initializer method that will load all properties that required to configure. [managed servers, machines, cluster]
- Create a singleton class that would allow single connection object that can be preserved and used for monitoring JVM, Threads etc.