85 questions
1
vote
1
answer
1k
views
Returning null in Bean annotated method
I have a web filter that I only want to execute when debug level is enabled. I was trying to implement a dummy filter to return to conform to Null Object pattern but I was getting many errors and lost ...
1
vote
0
answers
60
views
is this implementation of the Singleton and Object null Patterns Thread Safe?
Im trying to write a simple code to implement the Singleton and object null patterns.
the code should check if the new customer has a name, if yes put it in the real customer, and if not in the ...
1
vote
1
answer
174
views
C++ Nullptr vs Null-Object for potential noop function arguments?
TL;DR : Should we use fn(Interface* pMaybeNull) or fn(Interface& maybeNullObject) -- specifically in the case of "optional" function arguments of a virtual/abstract base class?
Our code ...
0
votes
0
answers
53
views
Not returning a null list but also not returning an immutable empty one and alternative approaches
I have a method that returns a List.
E.g.
List<Foo> getItems(Bar bar, X x)
I don't want the method to return null to avoid null pointer exception and do something like:
List<Foo> getItems(...
2
votes
2
answers
1k
views
Is there a safe "no id" @StringRes or @DrawableRes value for a null object pattern?
Suppose I wanted to implement a null object pattern of a model so as to guarantee an object that will do nothing, without requiring null checks on nullable fields.
interface Model(
val textId: Int,...
0
votes
0
answers
65
views
starting another activity (recyclerview list) by clicking on item
My main activity (MainActivity) contains Recycler view with list of images and text in cardview. I am trying to put separate onCLick listener on each cardview so that when any card view is clicked, ...
24
votes
18
answers
50k
views
Why my coreWebView2 which is object of webView2 is null?
I am creating a object of Microsoft.Web.WebView2.WinForm.WebView2 but the sub obect of this coreWebView2 is null
Microsoft.Web.WebView2.WinForm.WebView2 webView = new Microsoft.Web.WebView2.WinForm....
0
votes
2
answers
3k
views
system.text.json explicitly set null attributes while ignoring unset attributes when serializing
I am trying to serializing a POCO object into an update request.
My unset values are serialized as null, which causes them to be updated to null.
If I set IgnoreNullValues to true this fixes the ...
17
votes
2
answers
18k
views
Java Records and Null Object Pattern?
Is there any way to do Null Objects with Java Records? With classes I'd do it like that:
public class Id {
public static final Id NULL_ID = new Id();
private String id;
public Id(String id) {
...
1
vote
1
answer
327
views
EF Core optional ValueObject as identity
I am using value objects as identities and would like to know how to best deal with nulls in EF core.
For example if I have an employee with an optional title (mr, mrs, etc):
public class Employee
: ...
0
votes
2
answers
101
views
Null Object Pattern on _base_ values
Let's say we have following DTO object which is representation of a record in a database:
public class UserDto
{
public int Id { get; set; }
public DateTime? ExpireOn { get; set; }
}
So Id ...
0
votes
1
answer
95
views
how do i slightly change the postion of an object in after effects that is connected to a null object?
I am trying to only slightly change the poison of an object that is whipped to a null
thisComp.add(125,250).layer("Null 1").transform.position
and it wouldn't work.
right now a null is making sure ...
0
votes
1
answer
299
views
Javascript checking for null objects and caching values [duplicate]
In javascript re-introduction, I went through 2 examples that I have no clue when or where to use them. Below a quote:
The && and || operators use short-circuit logic, which means whether ...
1
vote
3
answers
587
views
Why not implement singleton pattern for the NULL object in Kotlin?
class Foo(val param1: String, var param2: Int) {
// class body
companion object {
val NULL = Foo("", 0)
}
}
Is the NULL object valid in Kotlin?
Although ...
-1
votes
1
answer
120
views
How to solve null references error? Im new at this [duplicate]
It says that my getOutletId() is null references and i already declared, i think.
So basically this is a booking step 4. For the first step, user need to choose outlet from firestore and choose which ...
3
votes
3
answers
376
views
Branch on null vs null object performance
Which is most efficient: using a null object, or a branch on nullptr. Example in C++:
void (*callback)() = [](){}; // Could be a class member
void doDoStuff()
{
// Some code
callback(); ...
1
vote
2
answers
336
views
Implement null object pattern
I found this question which implements a null object pattern in Kotlin in a certain way. I usually do it a little different in Java:
class MyClass {
static final MyClass INVALID = new MyClass();
...
0
votes
1
answer
485
views
Empty interface for Null Object pattern
I have some DTO object for transfer data with WCF.
public class Foo
{
//Many fields
}
WCF service method returns this object, and I have the valid case when this object should be null.
I want to ...
0
votes
0
answers
65
views
Attempt to invoke virtual method...on a null object reference problem
I have a problem with my code, where sometimes I get a null object reference and sometimes not (on the same thing) and I cant understand whats the problem because as I said, one time its working fine ...
0
votes
0
answers
40
views
null object pattern unable to solve the problem of multiple return types
Sometimes users prefer not to disclose marital status, which is fine in my domain. So I have data where user is either married or not and I have data where I don't know the status. My goal is to make ...
3
votes
2
answers
2k
views
Javascript: Using pattern Null object pattern, RORO, undefined etc. as returning parameter for a Get-function in case requested object „not found“
First of all, I’m not sure whether the topic belongs to StackOverflow or not. However, I’ve found some discussions regarding other programming languages that addresses the topic on StackOverflow but ...
3
votes
4
answers
7k
views
How to implement Null Object pattern on data class in Kotlin?
I have a Kotlin data class:
data class PaymentAccount(
val accountId: Int,
val accountNumber: String,
val title: String
)
This is what I'd do in Java:
Create an abstract class:
public ...
2
votes
1
answer
1k
views
get all table values from firebase null object reference firebase database [duplicate]
public class ShowBPGraphActivity extends AppCompatActivity {
public GraphView graphView;
public LineGraphSeries <DataPoint>lineGraphSeries;
public String systolicbp;
public String diastolicbp;
...
3
votes
2
answers
449
views
Eliminating NULL by using NULL object pattern
interface Parent{
void process();
}
class Child1 implements Parent{
void process(){
//process by method 1
}
}
class Child2 implements Parent{
void process(){
//process ...
3
votes
1
answer
2k
views
Null object pattern for functional paradigm
Using Typescript for an Angular ngrx application, i have to do a lot of checks wether a value i access or get passed is null/undefined, eg calling .map() on a list that might exist.
What is the way ...
1
vote
5
answers
1k
views
Handling associations w/ null objects in Rails
I'm using the Null Object pattern in my Rails application to implement the concept of a guest user account.
Like many apps, I have a method on ApplicationController called current_user.
In the case ...
-1
votes
1
answer
531
views
Delphi10 ObjectPascal: how do I just get to access the fields in a ADODataSet single record
So really happy with connecting to the DB and all that. My Grid object is fine and showing all records etc. Really happy with SQL. And the concept "DBs are all about sets"
My issue is:
I create an ...
2
votes
0
answers
808
views
Null Object pattern and Enums
I have a class Person with an Enum for a property. It is a non-nullable Enum.
I have some new requirements and I can easily take care of them by introducing a Null Object NullPerson with all the ...
-1
votes
1
answer
338
views
c# what object literal could stop a foreach loop from looping?
I know I could wrap the entire foreach loop in an if statement, but I'm wondering if there's some object literal value replacement for new List<string>() so that the foreach skips executing when ...
2
votes
1
answer
76
views
Does the null object pattern make debugging more complicated?
I was wondering if the null object pattern could actually make debugging more difficult in certain cases. For example, if a method returns an "empty" object rather than a null then it will not throw ...
8
votes
3
answers
7k
views
DAO with Null Object Pattern
After Reading:
Effective Java (See Item 43) - Joshua Bloch
Clean Code (Don't Return Null) - Uncle Bob
Avoiding != null statements
Null Object pattern
I was looking for an answer to the question ...
1
vote
2
answers
82
views
NullObject Pattern: How to handle fields?
Suppose we have Book class which contains year_published public field. If I want to implement NullObject design pattern, I will need to define NullBook class which behaves same as Book but does not do ...
2
votes
2
answers
523
views
Does Null Object Pattern break Interface Segregation principle?
The Interface Segregation principle states that:
Clients should not be forced to depend on methods that they do not use.
In the Null object pattern the Null class that implements the interface does ...
6
votes
2
answers
4k
views
rails text_field / text_ara empty string vs nil
I'm not even sure if I have a problem, but I just don't like that my text_fields and text_areas get saved in the db as empty string instead of nil.
I'm playing with the null object pattern and just ...
0
votes
2
answers
53
views
Template NullObject: Is it a sin?
I coded this little Template-NullObject in Java and wanted to ask you wether it would be considered a sin to use one of these.
When creating a NullObject, you typically make one which was specifically ...
2
votes
1
answer
2k
views
Ways to implement Null Object Pattern
Till now I have seen everywhere that the steps to create Null Object Pattern, for example in BST to remove null checks, are as follows:
Create an interface Node
Create two classes implementing the ...
-1
votes
2
answers
122
views
"Cannot convert from 'A' to 'B&'
I'm building an Entity-Component system using template metaprogramming. I keep getting either Cannot convert from [base type] to [type user requested]& or Cannot convert NullComponent to [type ...
1
vote
2
answers
2k
views
Rails instance methods conditional depending on attributes being set
I have a model that has several attributes that are optional when the model is being saved.
I have several instance methods that use these attributes and perform calculations but I would like to ...
4
votes
1
answer
161
views
How to achieve NullObject pattern with RxJava
Yea, that may sound a bit ambitious but here is what I want to achieve:
I have class which holds my hot Observable, it takes some time for class to prepare it correctly (create it in another place ...
5
votes
1
answer
223
views
Naming Convention for Null Objects in Rails?
For rails applications: does there exist a naming convention for naming your null objects that are mapped to model objects?
Example:
#app/models/blog.rb
class Blog < ActiveRecord::Base
end
#app/...
4
votes
0
answers
768
views
Null object pattern with entity framework code first
We've implemented the null object pattern in our domain model. We're using code first with fluent api to persist our domain model.
One of our entities has a navigation property - this navigation ...
25
votes
6
answers
8k
views
Null Object Pattern
There seems to be a growing community of people saying that you should never return null and should always use the Null Object Pattern instead. I can see the usefullness of the NOP when using a ...
2
votes
3
answers
2k
views
Guard clause and Null Object Pattern in Dependency Injection and C#
Using Constructor Injection, a dependency gets injected to a consumer like this (at least I hope I understood it correctly):
public class SomeConsumer
{
private IDependency someDependency;
...
1
vote
1
answer
4k
views
How do I mock a specific attribute on a model for a Rails view test?
I'm writing tests for a rails view, lets say the view is something like:
show.json.rep
r.element :user, @user do |u|
r.element :id, u.id
r.element :somefield1, u.somefield1
// a lot of ...
0
votes
2
answers
178
views
How to use Guava Optionals in a non-generic context?
I'm trying to use the Null-Objects from guava in the following method:
private void display(Optional<String> message) {
...
}
The method in which I am calling the method display(..) looks ...
2
votes
3
answers
119
views
NullObjectPattern and the Comparable interface
The problem I'm having has already been asked before: How to implement an interface with an enum, where the interface extends Comparable?
However, none of the solutions solve my exact problem, which ...
0
votes
1
answer
155
views
Null Object Pattern in a doubly linked list
I'm trying to use the null object pattern in a doubly linked list in c++, but I can't seem to find a way to use it while keeping the code clean.
The problem lies in the following piece of code:
node-...
3
votes
1
answer
171
views
Generic empty overloaded constructor and when not to use generics
I’m currently building a generic state machine and I’m using the constructor of the StateMachine with a generic parameter to set the fallback state at creation, in the event that there is nothing for ...
2
votes
1
answer
279
views
Null implementation of type boost::functions
I have something like this:
boost::function<void(void)> redStyle = boost::bind(colorStyle, "red");
boost::function<void(void)> blueBlinkingStyle = boost::bind(animatedStyle, "blue", ...
2
votes
1
answer
510
views
Creating objects with reflection
I'm trying to write a NullObject creation method, where I pass in a class name that implements an ICreateEmptyInstance interface (that is empty) and it walks it's properties looking for other classes ...