Issue Details (XML | Word | Printable)

Key: BOO-224
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Rodrigo B. de Oliveira
Reporter: Scott Fleckenstein
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Boo

allow for partial classes

Created: 14/Dec/04 07:38 PM   Updated: 05/Mar/08 06:58 AM
Component/s: Compiler
Affects Version/s: None
Fix Version/s: 0.7.5

Time Tracking:
Not Specified

File Attachments: 1. Text File partial2.patch (14 kB)
2. Text File partial3.patch (6 kB)

Issue Links:
Related
 


 Description  « Hide
add the "partial" modifier to type definitions such that you can spread the defintion of a class accross multiple physical files. example:

in SomeClass-1.boo

partial class SomeClass:
field1 as string
field2 as string

def someOp():
someOpInSecondFile()

def someOpInFirstFile():
pass

in SomeClass-2.boo

partial class SomeClass:
def someOpInSecondFile():
someOpInFirstFile()



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Scott Fleckenstein added a comment - 23/Dec/04 06:03 PM
I've completed work to enable this feature and will commit it pending community approval. The behavior is as follows:

-only class defintions (i.e. not structs, interfaces, or enums) can be declared partial.
-partial classe defintions can appear in the same file, in different files, or both.
-Nodes from all the files are simply concatenated together, so that if you declare foo() in 2 partial classes, the error will read like you had declared the same function within one traditional definition.
-You can declare base classes or interface implementations on any of the partial class definitions. All such declarations will be unioned, that is, the following is valid:

partial class foo (someInterface):
pass
partial class foo (someInterface, someInterface2):
pass

the merged class foo will implement both someInterface and someInterface2. If 2 or more different base classes are declared in each partial definition an error will be thrown just like you had declared 2 base classes in a full definition.


Doug H added a comment - 09/Sep/05 11:10 AM
Updated Scott Fleckenstein's partial classes patch against latest sources, added test cases, updated syntax files for new "partial" keyword. Everything works great!

Rodrigo B. de Oliveira added a comment - 10/Sep/05 08:26 AM
I do think partial classes are a very useful feature and it will certainly be part of boo some time soon.

I'm still not sure if requiring the 'partial' keyword in the type declaration is the way for boo to go.

I would like us to be able to do things like the following eventually:

namespace System

class String:
def MyCoolStringMethod():
return self.Trim().ToUpper()

Open classes.

I'm sure I'll be in a better position to suggest something more concrete after the PDC.


Rodrigo B. de Oliveira added a comment - 10/Sep/05 08:31 AM
If we decide to go with the 'open classes' approach, this code will be legal.

Doug H added a comment - 10/Sep/05 09:21 AM
Yeah, sounds interesting. Multimethods for adding methods to external classes maybe, and implicit partial classes for combining internal classes like this patch.
This version of the patch works the same as before but doesn't require any partial keyword, if it is useful.

Daniel Grunwald added a comment - 10/Sep/05 09:25 AM
I think the partial keyword should be required.
It allows you to quickly see that a class is NOT partial, so you don't have to spend time searching the other parts. That is good both for humans and IDE's.
And if you need a partial class, it's only 7 letters to add.