|
I want a million dollars. Send me a check.
|
|
|
|
|
OK. It'll be very bouncy.
Bar fomos edo pariyart gedeem, agreo eo dranem abal edyero eyrem kalm kareore
|
|
|
|
|
urgent reply
I don't see how that will help you publish your project though...
|
|
|
|
|
This reply is VERY Urgent.
I hope this satisfies your requirements.
NaliniNagarajan wrote: send me the procedure...
Try saying please, it will help.
Everyone's problem is urgent to themselves, but not to us that provide answers for free. If it's urgent obtain paid support otherwise be polite, make you subject line descriptive of your problem and wait for a reply.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Darn! I missed the urgency by 2 days!!
|
|
|
|
|
Hi all,
Lets say I have 3 classes which all share many attributes as well as having there own specific attributes. I realise that the thing to do is to have the 3 classes inherit, from a parent class, the shared attributes.
Now, say 2 of the classes also share some attributes but the third one does not, should I I place these attributes in each child class or place them in the parent class?
Obviously, placing them in the child classes will mean duplication of the varaibles, properties and any methods which act on these properties. But putting them in the parent class will mean that the third class, which does not require these attributes, will have access to them. Is this a problem?
I realise that I could in fact have another class between the child classes which share these extra attributes and the parent class, but this seems a little eloaborate when there are probably only 3 attributes to share.
Any advice is appreciated. Thanks.
|
|
|
|
|
If you're using VB.NET you could implement a base class and the others as interfaces.
To make it clearer, you could have BaseClass BClass and the interfaces that are shared as IShared, then you'd have class A inherit from BClass and Classes B & C inheriting from BClass as well and also implementing the interface IShared. You'd still have to implement the methods and properties, the interface is nothing more than a contract specifying the names of the methods/functions, their return values and the parameters they accept.
|
|
|
|
|
OK, thanks for your reply. But I don't think interfaces are the way to go as I'm wanting to share attributes rather methods/functions (although there MAY be methods/functions which perform calculations on these attributes, it is the attributes I am more concerned with).
Thanks again though for the reply.
|
|
|
|
|
This would still apply to attribute, that is assuming that by attributes you mean Get/Set Properties and not runtime parameters that affect the code. If the latter is the case, you might want to consider breaking it out into a helper or utility class that gets called.
|
|
|
|
|
Ah ok, I didn't realise that you can use interfaces to implement attributes (yes, get/set properties). Thanks again for your help
|
|
|
|
|
OK, I have to be pedantic now, just for the sake of proper understanding.
An Interface is just a contract. It doesn't implement anything, its a prototype. Think of it as an agreement between you and another class where all you care about is how to call the class, what parameters to send it and what to expect from it. Other than that, its a black box, you don't know and in theory shouldn't care how things are implemented, you simply care about invoking (Method/Property) and the result.
The class that implements the interface will still have to implement those methods in their own way. So, to follow up on our example of the classes A,B and C, B and C being the classes that inherit the interface will have to implement it in their own code.
Here's a quick example:
<br />
Public Class BaseClass<br />
'Class Implementation goes here<br />
End Class<br />
<br />
Public Interface IShared<br />
'Interface definitions<br />
Function DoSomething() as Integer
End Interface<br />
<br />
Public Class A<br />
Inherits BaseClass<br />
'Class A implementation<br />
End Class<br />
<br />
Public Class B<br />
Inherits BaseClass<br />
Implements IShared<br />
'Class B implementation<br />
Public Function DoSomething() as Integer<br />
Return 3 * 3<br />
End Function<br />
End Class<br />
<br />
Public Class C<br />
Inherits BaseClass<br />
Implements IShared<br />
'Class C implementation<br />
Public Function DoSomething() as Integer<br />
Return 5<br />
End Function<br />
<br />
End Class<br />
Pay attention to the Interface and the implementations in Class B and C
|
|
|
|
|
Yes, I do actually understand what an interface does, just didn't think it would be an appropriate approach for about 3 attributes/properties. But thanks again for your time
|
|
|
|
|
Sorry
My only excuse is that some of the posters show a surprising lack!
And you're very welcome
|
|
|
|
|
Liqz wrote: Now, say 2 of the classes also share some attributes but the third one does not, should I I place these attributes in each child class or place them in the parent class?
Obviously, placing them in the child classes will mean duplication of the varaibles, properties and any methods which act on these properties. But putting them in the parent class will mean that the third class, which does not require these attributes, will have access to them. Is this a problem?
If it doesn't sound right or seems like your copying and pasting the same code into multiple classes......then it probably isn't right.
Place them in the 'parent' class. There is no need to re-duplicate logic. You can inherit the class and use the mybase keyword.
Cheers!
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
OK, thanks. But if I put them in the parent class then the 3rd child class will also get access to these attributes which it doesn't need.
For example, I have 3 child classes: Contact, Organisation and Facility, which inherit from a parent class. Contact and Organisation have a credit limit attribute but Facility does not. Is it bad practise to put the credit Limit attribute in the parent class, giving the Facility class access to it?
|
|
|
|
|
Yes it is. Often enough in these cases, there is no free lunch.
|
|
|
|
|
One thing you could do it create the base class and build the interface as protected.
While doing it this way does force you to fully inherit from the base class even to get its full implementation public, it allows inheritors to decide what inherited attributes are publicly exposed, giving you a bit of control with regards to what attributes are propagated outwards to the public interface of the inherited classes.
It is a bit of a hack but one I have used successfully before.
|
|
|
|
|
Hi,
inheritance is not limited to two levels. You could do (pseudo-code):
class A
class B inherits from A
class C inherits from B
class C1 inherits from C
class C2 inherits from C
so B, C1, and C2 share everything in A
C1 and C2 share everything in C, but B does not.
|
|
|
|
|
Thanks. I had considered this but thought it to be a little over elaborate for the sake of about 3 attributes/properties. So was wondering if there were any other ways around it. I think this is the way I'm going to go though.
Thanks for the advice all
|
|
|
|
|
you're welcome.
|
|
|
|
|
I cant able to delete a subfolder inside a folder.
What i going is, opening a file from subfolder, reading it and closing the file and copying it to other folder and then deleting that file. Same i doing for all files in that subfolder. then checking that subfolder size if its size is zero, deleting it.. this is the code i used to delete the folder
path = "c:\newfolder"
For Each fld In path.SubFolders
If fld.Size = 0 Then
fld.Delete : here i am getting permission denied, error 70
End If
Next fld
I am closing all the FileSystemObjects.
jishith
|
|
|
|
|
Is this in Vista? Run the file as an administrator?
|
|
|
|
|
Hi,
there could be several reasons why a folder cannot be deleted:
- it contains some files; checking its size against zero is not correct, what if there is an empty file?
- the file you tried to delete in an attempt to empty the folder did not get deleted for one of many reasons
- the folder is in use, e.g. there is a Windows Explorer window open showing it.
- the folder was created by some one else, you don't have delete rights for it.
|
|
|
|
|
Hi,
Thanks for replying. but..
1) Checking the file folder size with 0 is not correct, here the folder is empty
2) I manually creating the folder, so no right issues
3) I can delete that folder, whn i am running my application for the next time. Only the first instance its showing permission denied. First i thought some oject is not releasing. But i making all the object i used in the function to nothing. Still it showing permission denied.
If there are four folders, its deleting three folders and when its come to the last one, the permission is denied.
How i make sure the folder is not in use? Or how to release the in use folder?
Jishith
|
|
|
|
|
Perhaps you are the one who has the folder in use? Can a reference to fld keep the folder "locked for editing"?
Second question;
For Each fld In path.SubFolders
If fld.Size = 0 Then
fld.Delete <code>- Is this allowed in a foreach?</code>
End If
Next fld
I are troll
|
|
|
|