question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: Add factory methods to ListedItem

See original GitHub issue

What’s the Problem?

There doesn’t presently exist a standardized way to create a ListedItem from external constructs such as IStorageItem-derived types, WIN32_FIND_DATA, and IShellItem. We currently expose numerous public properties on ListedItem and expect users of it to automatically and correctly populate all of them.

This expectation adds a level of redundancy and duplication everywhere we have to create ListedItems, and is not good architecture.

Solution/Idea

We should discuss improving code quality in this area with all of the tasks below:

1. Define factory methods inside ListedItem.cs (draft)

public static ListedItem FromFindData(WIN32_FIND_DATAW findData, string dateReturnFormat = null)

public static ListedItem FromStorageItem(IStorageItem storageItem, string dateReturnFormat = null)

public static ListedItem FromShellItem(IShellItem shellItem, string dateReturnFormat = null)

2. Make all properties on ListedItem read only

3. Add a way to determine what type of external construct(s) back a ListedItem instance

Alternatives

Add multiple constructor overloads to ListedItem: This idea might not be ideal because we may access the filesystem directly when constructing the item.

Priorities

Capability Priority
This proposal will allow users of ListedItem to easily create one from external constructs in a standard way Must
Add a way to determining the backing OS filesystem construct(s) Could

Files Version

v2

Windows Version

Windows 11 21H2

Additional comment

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
cinqmilleanscommented, Jan 31, 2022

@duke7553 Thank you. As mentioned on Discord, that’s what I was planning to do.

1reaction
lukeblevinscommented, Nov 3, 2021

@d2dyno1 I support that idea. ListedItem has kind of a mixture of entirely exposed UI and non-UI properties.

The alternative practice you mentioned is more typical. It appears to be a sound design, and we could separate the implementations in a UI focused way rather than arbitrarily.

Good feedback as always. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Factory Pattern. When to use factory methods?
In Factory class you need to change the Factory but in the factory method, no, you only need to add a new subclass....
Read more >
design patterns - Static factory method in base class
The GoF book does list the Factory Method Pattern and likens it to a “virtual constructor”. The whole point here is that the...
Read more >
Factory Method
Factory Method is a creational design pattern that provides an interface for creating objects in a superclass, but allows subclasses to alter the...
Read more >
The Factory Method Pattern and Its Implementation in Python
The new design of Factory Method allows the application to introduce new features by adding new classes, as opposed to changing existing ones....
Read more >
Exploring the Factory Method Design Pattern
Implement the factory method: The factory method is implemented in each subclass, and it's responsible for creating objects of a specific class.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found