[Tutor] Questions Regarding ASPECT ORIENTED PROGRAMMING (AOP)
Alan Gauld
alan.gauld at btinternet.com
Wed Feb 25 20:16:53 CET 2015
On 25/02/15 13:00, Mishal Chowdhury wrote:
First, I'm not sure that either of these questions have to do with
Aspect Oriented Programming per se. Note however that Python
does not offer any specific support for AOP. (You can't explicitly
define an 'Aspect' like you can a class for example)
> 1. Is it Possible to call a function which is defined in a child class from
> a parent class through a web service?
Yes, if you write a suitable web service, otherwise no.
And if you set up the classes such that a feature in the
parent class knows about the child class function (do you
mean method?) Remember that by default Python classes do
not implement data hiding so it is very easy to peek
inside a class.
> 2. Can I Create an Aspect Class and create a child class of the Aspect
> class and allow another class to access the child aspect class methods?
Yes, but these would just be normal python classes being used to
simulate AOP type features. There is nothing in Python to
explicitly support that.
And do you really mean classes here or are you really meaning
instances? When you start mixing styles like that you need
to be very precise with your terminology.
> Could I please get an example code to see whether the above situations are
> possible or not?
You can try to write your own code and we will help you make it work.
Python offers many ways to implement Aspects such that the users of
the Aspects are minimally aware of them, such as decorators, and in
some cases context managers, and even metaclasses. In other
situations multiple inheritance can be used. But in each case
you are faking real AOP style, and it will take some effort
to write. Python is not AspectJ.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list