Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [properties]

The tag has no usage guidance.

0
votes
3answers
151 views

Interface properties implementation

As the code below, class Foo1 implements interface IFoo, which has a property of IData. public interface IFoo { public IData Data { get; set; } } public interface IData { ... } public class ...
2
votes
1answer
103 views

Whether to replace mutually exclusive but poorly related properties with an interface

A few years ago I designed a class which had two properties. The two classes ChildA and ChildB had a rich protocol with many properties and methods, but were only distantly related in my model. They ...
5
votes
2answers
2k views

readonly vs. private getter-only property in C# 6

C# 6 added auto-property initializers and so we can do private List<LinearLayout> layouts1 { get; } = new List<LinearLayout>(); Is this better or worse than private readonly List<...
0
votes
2answers
173 views

When is it not Pythonic to use properties instead of a method that doesn't take arguments?

It's widely agreed that Python's properties are not merely a kludge for working around the past mistake of exposing of publicly exposing data members. But then when is it not Pythonic to use a ...
2
votes
2answers
331 views

Is there any reason to avoid private getters?

Even though I could write something like this (In C#. There are, of course, equivalents in other languages): public int SomeNumber { private get; set; } I have never encountered something like this. ...
1
vote
3answers
3k views

Are protected properties evil? [duplicate]

Introductory piece of code: class BaseClass { protected Foo MyFoo { get; } } class ChildClass : BaseClass { void SomeMethod() { MyFoo.DoStuff(); //Here, I have no idea ...
0
votes
1answer
93 views

Do all Get/SetAccess, Access, and Dependent property attribute combinations have valid use cases?

If You are Unfamiliar with OOP Matlab For those not familiar with matlab, matlab provides a variety of access attributes when creating member variables. All member variables are essentially C# ...
11
votes
5answers
3k views

Is it a bad idea to use getters/setters and/or properties at all? [duplicate]

I am perplexed by comments under this answer: https://softwareengineering.stackexchange.com/a/358851/212639 A user is arguing there against the use of getters/setters and properties. He maintains ...
2
votes
3answers
287 views

Differentiate between variables used and not used in properties

I am learning about c# and I am a little confused about (non-automatic)properties and the local variable that the property uses. When I use properties, I put an underscore for all the private ...
0
votes
1answer
133 views

Constructors or setters for entity classes? [duplicate]

I know this has been asked a lot of times but we are talking about entity classes here. Plain dumb objects containing nothing but primitives for properties. The purpose here is to store data. Our ...
5
votes
4answers
2k views

Multiple properties/methods giving the same result

I'm trying to ascertain whether the use of multiple references to the same property is code smell / an anti-pattern, based on the needs of the organisation. As an example, consider: abstract class ...
-1
votes
2answers
99 views

What is this command called?

I've seen this syntax in many places, such as when using javscript, thymeleaf(spring), properties files etc. //ex; in properties file. Where are the values coming from? ${someText} ${set.config....
3
votes
1answer
138 views

Should I be unit testing “non dynamic” properties? [duplicate]

There is an ongoing debate about the following property, and if it should be tested or not. We're working in C#. MyClass prop => value; Should I be writing the following unit test : IMyClass ...
6
votes
1answer
19k views

The correct use of application.properties file?

Java programmers are encouraged to store all their configurable parameters in an application.properties file from which they either load properties during runtime or they load during program start and ...
0
votes
1answer
277 views

What is different from Config and Backing Service?

I am learning the 12 factor rule. I cannot get my head around the difference between storing configuration into environment and Backing service. Also how would u store properties into "Environment"? ...
14
votes
5answers
800 views

Best practices for handling large number of structured configuration/property files

Imagine a system that has a large number of servers. Each of them has a number of settings: Some specific to the server Some specific to the region Some common across all of them Maybe you can have ...
3
votes
2answers
2k views

Correct usage of Property vs Field vs Function in C#

I've been bothered by this line of code I've written and I've been a bit confused into what should be written instead. class SomeClass { IBeneficiary _latestBeneficiary => new Beneficiary(...
1
vote
2answers
4k views

Is it a good programming practice to store java properties keys in ENUM for validation once application starts?

Sample Java properties file which is read by the properties class appl.component1.property1=value1 appl.component1.property1=value2 Custom class which extends the java.util.Properties class adding ...
4
votes
2answers
103 views

Java Properties Files for Both Operations and Developers

We have an enterprise application. Maven build, about 20 submodules with more submodules. We have a dedicated Ops (operations) which deploys our application to 10 clusters. Installations are running ...
3
votes
1answer
251 views

When adding a property to an interface in C#, is that consider major, minor, or patch using semantic versioning?

My team and I are trying to follow semantic versioning 2.0.0 to keep tabs on our library versions. We primarily use C# for our development and are currently in a situation where we are going to add a ...
2
votes
5answers
705 views

Frequency of getter access

As getters in C# may be relatively costly, I wonder if they will be called every time or if the compiler will do any optimizations. Let's have a look on this: List<A> CurrentList{ get; } void ...
0
votes
0answers
369 views

Are there any downsides to JavaFX Properties as a replacement for Beans?

So I am really annoyed that Java doesn't support C# like properties. I tried a lot of things to emulate that behavior and this is the best I came up with: import javafx.beans.property.*; //immutable ...
0
votes
0answers
47 views

Use Local Parameters If Global are empty?

Simplified Case with Immutable Class final class Secret implements IFoo { private $header; public function __construct(array $header = []) { $this->header = $header; } ...
2
votes
0answers
117 views

Interface Methods vs Data Objects

Building a UI editor for Android and basically there are interfaces such as this: interface Item { fun decorate() fun translate(x: Int, y: Int) fun rotate(rotation: Float) fun scale(...
1
vote
1answer
139 views

How should I handle one extra bit of information of an object?

I have two classes: Employee and Conversation. Conversation has a property with the employees which participate in the conversation: List<Employee> Participants { get; set; }. On the database, ...
-1
votes
1answer
815 views

Java properties - no more get/set in names?

I don't getFoo/setFoo naming convention, that is so spread that it become a standard. Instead, I am using more and more just: foo() and foo(value) for reading and setting value. I also see this trend ...
6
votes
4answers
538 views

javascript closure = c# properties?

For anyone who is expert in both Javascript and C#: Can we think of JS closures the way we think about Private and Public Properties in c#? A closure refers to an inner function (public property) ...
0
votes
0answers
30 views

Whose responsibility is an element's margin?

I'm working on a graphics library that works a bit like the Android-type libraries and I ran into a question regarding the topic of margins and whose responsibility they should be. It seems very ...
7
votes
3answers
1k views

Why aren't properties implicitly convertible to delegates

We all know that properties in C# get compiled to actual plain old methods. But unlike method(-group)s, they can't be given as arguments to other methods that expect a delegate like a Func<T> or ...
6
votes
5answers
162 views

DB design: what is a good way to handle properties for game?

I must persist handful of properties for several games in relational DB. No other type of DB can be used. Number of games will be around 4-5, and number of properties is (for now) kind of small, but ...
2
votes
1answer
52 views

Expose one whole object or several properties of that object?

I'm currently refactoring on an older project, which has classes that expose both a single object and also multiple properties from that object. Ex: public class Foo { private MyObj myObj; ...
2
votes
1answer
462 views

Is a PropertyChanged event handler bad if it is used for updating the database?

I have a class with several fields. public bool Active { get; set; } public List<Group> Groups { get; set; } public string FirstName { ...
2
votes
2answers
352 views

What is the best approach to update a database field when a corresponding class property changes?

I have a class with several fields. public readonly byte Id; public bool Active { get; set; } public List<Group> Groups { get; set; } public ...
1
vote
2answers
1k views

Don't auto-implemented properties violate encapsulation?

In C#, when a field getting or setting requires logic, we use properties. For example: private int _age; public int Age { get { Console.Writeline("Club member is {0} years old", _age);...
3
votes
1answer
649 views

Can an object contain a property that is another object?

I am new in the object oriented world. I am interested on learn the foundations of object oriented programming independently of any language. But for the moment I am doing the implementation on VB.NET....
1
vote
1answer
117 views

Should “magic” getter functions be used for dynamically calculated values or just existing properties?

For example, if I had a Customer class and wanted to get all orders by them. Would it be better to do: class Customer{ public function getOrders(){ return results from db query } } .....
4
votes
1answer
4k views

Is it pythonic to use properties to limit the mutability of class attributes (variables and methods)?

Some Explanation I'm somewhat new to python and to programming (I've been at it for a little over a year). I just recently discovered python properties, and I've been using them to limit the ...
5
votes
2answers
19k views

Throwing an exception if some property is not present in a properties file

it's not a big programming problem, but I'm curious if it should be done better. So I have a config file which I'm reading via java.util.Properties class. When property is not present in a file ...
5
votes
1answer
1k views

How to load environment configuration

In Java the typical way of storing configuration is by using property files. So I have several such files, one for each environment type (dev, test, prod, ...). This configuration is needed in ...
2
votes
1answer
443 views

Could there be a use case for C# style auto-properties in Python

I've been doing a lot of work in C# recently (my primary language is Python) and I love that I can do something like public string MyProperty{ get; set; } Going back to Python I miss that sort of ...
24
votes
4answers
5k views

How do I handle setters on immutable fields?

I have a class with two readonly int fields. They are exposed as properties: public class Thing { private readonly int _foo, _bar; /// <summary> I AM IMMUTABLE. </summary> ...
7
votes
4answers
455 views

Is guaranteeing immutability a justification for exposing a field instead of a property?

The general guidance for C# is to always use a property over a public field. This makes sense- by exposing a field, you're exposing a lot of implementation detail. With a property, you encapsulate ...
1
vote
2answers
1k views

Python - best way to have interdependant variable in a class

Newbie Python questions: I want to model something that can have a several inter-connected instance variables and if I set one, I want to recalculate the others. Any can be set. E.g. a circle - each ...
1
vote
1answer
71 views

Down Sides to Using Properties as Opposed to Method Variables [closed]

I am debating the pros and cons of a couple of utility classes I have. The classes have a couple of properties which are set prior to calling the class methods. However, I was wondering if there are ...
4
votes
2answers
272 views

Should I use properties for the properties of properties?

Sometimes I use some indirect properties to set or get some other sub-properties, I give an example class Page { public string MainText { set { MainParagraph.Text = value; } get { return ...
4
votes
2answers
2k views

Is checking that a property doesn't throw an exception a valid unit test?

I'm writing tests for the following class: public class Foo : INotifyPropertyChanged { private int _failCount; private int _totalCount; public double FailRate { get { double ...
11
votes
7answers
2k views

How did OOP evolve to include the notion of Properties

I've come from a C++ background and am going all out C# in my current job and I've just been reading a lot of Q&A about what's the difference between public fields and properties and all the back ...
0
votes
1answer
277 views

Async properties in interfaces to cater for the possibility of expensive first-time evaluation: Is this a good idea?

First of all, sorry if this post is too long. I'll start with the… Short version: Is it generally advisable or a good idea to design an interface property as asynchronous simply because we cannot be ...
2
votes
3answers
253 views

.NET Framework standard container type for multi-value property?

I'd like to create a simple class property which can contain multiple values set from the outside. (Values are of the same type.) Example of property name and contained items: KnownHidScanners "\\?\...
0
votes
2answers
1k views

Inheritance is a null property in the parent a bad practice?

I am not a very experienced programmer. So I ask. The field in question is the "Amount" field. I store an amount only in a couple levels of the derived class. The code is a slice of the POCO ...