473,385 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Partial Classes - Aspects

I'm currently writing a small toy application to support symbolic
algebra. Therefore I implemented some classes Term, Var, Number, Sum,
Product, Power. These classes are tightly coupled. So it is not
possible to organize them in distinct files. This would result in
cyclic imports.

To manage the complexity I implemented some sort of aspect oriented
programming (perhaps aspect oriented programming is not quite right in
this context...). That is I implemented a mechanism to dynamically add
methods to existing classes. This is similar to the thread "Partial
classes" discussed in this list. Therefore hereby offer some use case
for partial classes.

The aspects I already implemented are amongst others: pretty printing,
differentiation, expansion of terms. The aspect for expansion looks
like this:
# -*- coding: iso-8859-1 -*-
__aspect__ = "Expand"

class TermExpand:
def expand(self):
return self

class SumExpand:
def expand(self):
...

def expandSum(term, sum):
# some helper function
...

class ProductExpand:
def expand(self):
...

class PowerExpand:
def expand(self):
...

The code to import an aspect into existing classes accepts as a
parameter the name of a module. The module will be imported.
Afterwards the code iterates over all elements defined in the module.
If it is a (specially named) class all methods will be copied to the
original class. If it is a (top level) function it will be copied into
the global namespace. E.g. the method expand of the class TermExpand
will be copyied to the base class Term.

The difficulty with this approach is that the classes' methods and the
functions do operate in the wrong global namespace. Since these
functions/methods are located in their own module they get their own
namespace. To correct this I have to use new.function() to create new
methods/functions with the correct namespace (which is the base
module's namespace).

So my questions boil down to this:

* Do you think this is a sound approach to structure my code?
* I don't like the necessity to modify the functions. Is there a
simpler approach?

Thanks,
Peer

Jul 29 '06 #1
0 1360

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: nospam | last post by:
I got three (3) files (1) Untitled.aspx (2) Untitled.aspx.1.cs (3) Untitled.aspx.2.cs These three files must be used together to make file #1, Untitled.aspx, page work via J.I.T. when the...
9
by: Gomaw Beoyr | last post by:
Two question about the "partial classes" (in the next wersion of ..NET). Question 1 ========== Will partial classes (in the next version of C#) have to be declared "partial" in ALL places. ...
16
by: pawel.pabich | last post by:
Hajo, I would like to have 2 my own partial classes. For example: Default.aspx.cs Default2.aspx.cs and they both will relate to Default.aspx page.
10
by: ptass | last post by:
Hi In asp.net 2.0 an aspx files .cs file is a partial class and all works fine, however, I thought I’d be able to create another class file, call it a partial class and have that compile and...
1
by: Bishoy George | last post by:
In a web application using asp.net 2.0 All my classes are partial classes. - I noticed that partial class cannot be inherited... is that true? - I tried to remove the partial keyword , and I...
9
by: Fat Elvis | last post by:
I'd like to extend some of my Asp.net pages by using Partial Classes. Example ASP.Net Page: public partial class Admin_Customer : System.Web.UI.Page { protected void Page_Load(object sender,...
5
by: Sagar | last post by:
I am working on a migration project for a huge asp.net application now running in framwework 1.1 to dotnet 2.0 As a first step, I opened the .sln files of the project in VS.Net 2005. The...
2
by: Peted | last post by:
Hi, im moving a project from vs2005 to vs 2008. is doing so i have come across a compiler error regarding partial classes that i dont understand if anyone can explain it to me please the...
10
by: JDeats | last post by:
So I have a class that spans over two partial classes in code, here's an example (do not read much into this, the code is of no practical use, this is just a simple example of where my confusion...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.