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

protected fields

Are protected fields not only relevant when using inheritance?

I am currently changing some code that use inheritance to code that does not
use inheritance and don't see the point in keeping the fields protected.
Aug 2 '08 #1
2 1860
Hello saneman,
Are protected fields not only relevant when using inheritance?

I am currently changing some code that use inheritance to code that
does not use inheritance and don't see the point in keeping the fields
protected.
Yes, and you may want to change it to private.
Aug 2 '08 #2
Jianwei Sun <js***********@gmail.comkirjutas:
Hello saneman,
>Are protected fields not only relevant when using inheritance?

I am currently changing some code that use inheritance to code that
does not use inheritance and don't see the point in keeping the fields
protected.

Yes, and you may want to change it to private.
Even in case of inheritance, protected data members are often not a good
solution as it might make it impossible for the base class to ensure its
invariants.

A protected data member makes sense only when assigning *any* value to it
would not break the class invariants. Note that if this is the case one
could as well make the data member public instead of private when
redesigning the classes to not use inheritance. This would avoid writing a
pair of trivial set/get functions.

Paavo
Aug 3 '08 #3

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

Similar topics

1
by: AIK | last post by:
I have the following two classes: package birdpack; public class Bird { Bird() {} protected int nFeathers;
4
by: MS | last post by:
Access 97 I'm trying to check a table and add fields if necessary using code to a BE MDB. At the moment I'm reconnecting to the BE using code based on code written by Peter Vukovic...
4
by: Glen | last post by:
Hello, Can anyone tell me if there is a way to enumerate a member collection for a protected class? For example, the Cursors class is protected and must be called directly, but it does not...
4
by: TS | last post by:
what would be the scenario that you would want to declare a variable of a class in that fashion instead of a public property accessor?
2
by: GG | last post by:
I have an abstract class that looks like this protected DateTime startDate = DateTime.Now; protected DateTime endDate = DateTime.Now; classConstructor(DateTime startDate,DateTime endDate) {...
6
by: Murphy | last post by:
I've read through the google posts on this topic and am still unclear of the solution. Simply I have a user control that contains form controls and I would like to reference the values in the...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
16
by: Fir5tSight | last post by:
Hi All, I have a small C#.NET program that is as follows: using System; class A { protected int x = 123; }
8
by: Mayur H Chauhan | last post by:
All, For my knowledge, if I declare Class as follow, then it thows compilation error. Protected Class Book End Class Even same for...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.