473,398 Members | 2,404 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,398 software developers and data experts.

Access Modifier Question

I am thinking there isn't a way to do this but will pose the question
anyways.

I have a component I'm building that contains my business entities. I
have an entity that I want to inherit properties from another. I have
done so like this:

public class FirstEntity : SecondEntity
{
private string _someValue = string.Empty;

public FirstEntity(string someValue, string inheritedValue)
{
InheritedValue = inheritedValue;
_someValue = _someValue;
}

public string SomeValue
{
get
{
return _someValue;
}
}
}

public class SecondEntity
{
string _inheritedValue = string.Empty;

public string InheritedValue
{
get
{
return _inheritedValue;
}
set
{
_inheritedValue = value;
}
}

The problem is, I would prefer not to make the SecondEntity a public
class. I don't want to give anyone the ability to create this class
themselves. I've tried various access modifiers...if I make the second
class an interface, then of course, I have to create the properties I
inherit from it within the FirstEntity, I'd prefer not to do it that
way. Internal or Protected prevent anyone using the FirstEntity class
to see the inherited properties.

Is there some way to do what I'm thinking?
}

/// <summary>Date the script was written.</summary>
public string Date
{
get
{
return _date;
}
set
{

Oct 24 '06 #1
3 1385
Normally, if you don't want anyone to instantiate a class you would just have
a single private constructor for the class.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"Doug" wrote:
I am thinking there isn't a way to do this but will pose the question
anyways.

I have a component I'm building that contains my business entities. I
have an entity that I want to inherit properties from another. I have
done so like this:

public class FirstEntity : SecondEntity
{
private string _someValue = string.Empty;

public FirstEntity(string someValue, string inheritedValue)
{
InheritedValue = inheritedValue;
_someValue = _someValue;
}

public string SomeValue
{
get
{
return _someValue;
}
}
}

public class SecondEntity
{
string _inheritedValue = string.Empty;

public string InheritedValue
{
get
{
return _inheritedValue;
}
set
{
_inheritedValue = value;
}
}

The problem is, I would prefer not to make the SecondEntity a public
class. I don't want to give anyone the ability to create this class
themselves. I've tried various access modifiers...if I make the second
class an interface, then of course, I have to create the properties I
inherit from it within the FirstEntity, I'd prefer not to do it that
way. Internal or Protected prevent anyone using the FirstEntity class
to see the inherited properties.

Is there some way to do what I'm thinking?
}

/// <summary>Date the script was written.</summary>
public string Date
{
get
{
return _date;
}
set
{

Oct 24 '06 #2
That will definitely work, thank you. I was kind of wondering if there
was a way to make the properties non-public as well, but using a
private constructor should at least prevent them from being accessed
any way other than through the class that inherits them. Thanks!

Oct 24 '06 #3
Hi Doug,

It should be a single, protected constructor if you want to derive from the
class.

--
Dave Sexton

"Doug" <dn******@dtgnet.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
That will definitely work, thank you. I was kind of wondering if there
was a way to make the properties non-public as well, but using a
private constructor should at least prevent them from being accessed
any way other than through the class that inherits them. Thanks!

Oct 24 '06 #4

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

Similar topics

2
by: Dan Disney | last post by:
I have read conflicting information on the access scope of VB.Net class declarations when no access modifier is specified. MSDN library documentation states "Classes that do not specify an access...
3
by: N Khan via .NET 247 | last post by:
Hi, I know the usage of access modifier ?public? in DLL assembliesbut I am a bit puzzled that if let say I have a public class inan exe assembly then what purpose access modifier ?public?...
1
by: Ashkan Daie | last post by:
Hi All, Is there an internal access modifier in managed vc++ like vc#? Thanks, Ashkan
1
by: Mark Kamoski | last post by:
Hi-- Please help. What is the default access modifier value for a Sub or a Function when one has not explicitly been set. In MSDN, in "Access Types", it states... "If no access modifier...
3
by: Mr Newbie | last post by:
I am messing around with Web User Controls at present and (think) I have discovered the following. 1.) The identifier for the control in the code behind must match the ID for the control on the...
5
by: Harold Hsu | last post by:
Hi all, What's the default access type of a property declared in an interface? The one I'm looking at is IBindingList: Public Interface IBindingList .... ReadOnly Property AllowEdit As...
5
by: dost | last post by:
can u tell me the diffrence between...... private public and protected .........in........these.......which one...is access modifier....and which one..is specifier....... and....the diffrence...
3
by: RitualDave | last post by:
This compiles and runs successfully in VS2005: ref class A { private: ~A() { this->!A(); } // private! !A() { } // private! }; ....
9
by: JT | last post by:
Here is the overall structure I will be referring to: End-program ProvideWorkFlow.dll Forms and methods that properly manipulate calls to methods in AccessUtils AccessUtils (a web service)...
5
by: wpmccormick | last post by:
What is the cleanest way to gain access to object methods and properties across classes and files in the same namespace? Example: A form object frmForm in file frmForm.cs creates obj1 defined in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.