object-oriented – Class inheritance in C # (possibly generic)

I work on a code segment where it performs a number of tasks and then associates individual results to build a complete task result object. There is no simultaneity, so it is simply the best use of the inheritance / class model.

Below the skeleton of the code that I wrote, it goes in loop Iliste where everyone ITask returns a ITaskResultthe main method will then have to consider the type of each ITaskResult and set the property to CompleteTaskResult Consequently.

The goal is to keep the code easy to understand and easy to add new Task / TaskResult.

What I do not enjoy is the part where you have to check the type of ITaskResult individually, then set the value to CompleteTaskResulthe seems a little heavy with a lot of repetitions.

Is there a better way to structure this code?

Thank you.

                                ITask public interface
{
ITaskResult Execute ();
}

Public class AlphaTask: ITask
{
public ITaskResult Execute ()
{
returns a new AlphaTaskResult ();
}
}

Public class BetaTask: ITask
{
public ITaskResult Execute ()
{
return new BetaTaskResult ();
}
}

Public class GammaTask: ITask
{
public ITaskResult Execute ()
{
returns new GammaTaskResult ();
}
}

public interface ITaskResult
{
}

Public class AlphaTaskResult: ITaskResult
{
}

Public class BetaTaskResult: ITaskResult
{
}

Public class GammaTaskResult: ITaskResult
{
}

Public class CompleteTaskResult
{
public AlphaTaskResult AlphaTaskResult {get; together; }
public BetaTaskResult BetaTaskResult {get; together; }
public GammaTaskResult GammaTaskResult {get; together; }
}

static empty Hand (IList Tasks)
{
var taskResults = tasks.Select (x => x.Execute ());

var completeTaskResult = new CompleteTaskResult ();

foreach (var taskResult in taskResults)
{
if (taskResult is AlphaTaskResult alphaTaskResult)
{
completeTaskResult.AlphaTaskResult = alphaTaskResult;
Carry on;
}

if (taskResult is BetaTaskResult betaTaskResult)
{
completeTaskResult.BetaTaskResult = betaTaskResult;
Carry on;
}

if (taskResult is GammaTaskResult gammaTaskResult)
{
completeTaskResult.GammaTaskResult = gammaTaskResult;
Carry on;
}
launch a new exception InvalidOperationException ("unsupported task")
}

}

Edit: The intention is that one can pass a number of tasks in the form of: Iliste to the library and then recover concrete results back CompleteTaskResult CompleteTaskResult may have null properties if no specific task related to the properties has been executed. The principal appellant is well aware of the concrete type of ITask have been sent so that he also knows what properties of CompleteTaskResult query the results

5th dnd – A cleric taking the ritual Casting class assistant, is he able to scribe shared spells?

I would like to take the ritual master trick at level 4 to access wizard spells for more utility. Can my cleric spend the material cost to add shared rituals such as Detect Magic, Detect Poison, Identify, Sweet Rest … in the ritual book or should I find a written source based on a wizard?

design templates – Which form of unique instance class for an Android cache?

The application must communicate with a Bluetooth device with matching data (configuration, metrics, service logs, status telemetry) – and must cache the resulting data so that the user does not go from one activity to another. other. previous activity, or the data was obtained in a previous activity (for example, the activity "Summary" consists of retrieving pieces of data from others).

This means a cache object that should contain this data – and be a single instance class.

It has come to my mind that singletons are bad. But with Android applications having multiple entry points, I can not guarantee a single initialization path for the application or the lifetime of the object. So I do not know if the singleton is still wrong here – or if so, how do we approach the single instance class on the right in this scenario. What form of single-instance object should I use to boot it to creation and access it everywhere?


Xamarin, C #, if that is important.

css – adding an extra class to get the thumbnail of the message

I think I've already solved the problem, and now I have a problem with customizing the width and height of the image, here is my latest code.

    $ prev_post = get_previous_post ();
previous_post_link (
get_the_post_thumbnail ($ prev_post-> ID, 'custom size image', array (
& # 39; class & # 39; => & # 39; object rounded-lg & # 39;
& # 39; sizes & # 39; => Width = "371" height = "270" & # 39;
)). & # 39;

%link

& # 39 ;, & # 39; & # 39% Title ;, false )

but the part 'sizes' does not seem to work, help yourself please

object-oriented – C ++ model for configurable class functionality at compile time

Due to the limited resources (built-in), I wish to make some features that an optional class provides. The decision to include this optional feature must be taken at compile time.

For example, I have a simple pool memory allocator with optional statistical support. Statistical support must be available for x86 and ARM debug versions, but not for ARM version versions.

The following code is an excerpt from the current C-language-based implementation, showing the type of interaction between the pool itself and a statistic member structure that is conditionally included:

struct fmpool {
// ...
#ifdef FMPOOL_SUPPORT_STATISTICS
fmpool_statistics stats;
#end if
// ...
}

int fmpool_alloc (fmpool * pool, void ** alloc_block, size_t alloc_size)
{

// allocate

#ifdef FMPOOL_SUPPORT_STATISTICS
selected_pool-> stats.blocks_used ++;
if (selected_pool-> stats.blocks_used> selected_pool-> stats.blocks_used_peak)
{
selected_pool-> stats.blocks_used_peak = selected_pool-> stats.blocks_used;
}
debug_log_pool_info (selected_pool);
#end if

// ...
}

I am not sure which model is best for this use case, but I would like to lighten the allocator code by removing the statistic code from the allocator itself.

In addition, the code is awfully cluttered with #ifdefs, so it is desirable to minimize the interaction between the allocator code and the allocator's statistical code.

c ++ – A minimalist type of class reading-copy-update

This is a synchronization class inspired by reading, copying, updating (RCU):

#understand 


model
RCU class
{
private:

std :: atomic  curr;
std :: atomic  prev;
std :: atomic readers;

public:

RCU ()
: curr (new T),
prev (nullptr),
readers (0)
{

}

~ URC ()
{
delete curr;
delete prev;
}

empty padlock ()
{
readers ++;
}

cancel unlocking ()
{
lecteurs--;
}

T * get ()
{
return curr.load ();
}

T * clone ()
{
returns a new T (* curr.load ());
}

exchange of bool (T * t)
{
/ * If prev is full, an exchange is still pending. Clean the memory and
give up the operation. * /

if (prev.load ()! = nullptr)
{
delete t;
returns false;
}

/ * Stores the current pointer in prev. Readers could still be reading
through the pointer. * /

prev.store (curr);

/ * Curr contains the proposed new value. Nobody reads this
now. * /

current store (t);

/ * Spin until there are no more readers to * preview. Free the
memory, he says and says goodbye. * /

while (readers.load ()> 0);

T * old = prev.load ();
prev.store (nullptr);
delete old;

return true;
}
};

The idea is to have multiple threads of readers repeatedly reading some shared data, while a writing thread rarely updates them. The write thread takes care of cleaning the memory when no reader reads. Readers are "followed" through the lock() and open() methods. The RCU class must synchronize threads without locking.

Use:

struct data
{
int x;
int y;
int z;
};


UCR rcu;


void writer_thread () // the author rarely works
{
while (true)
{
Data * data = rcu.clone ();
// modify the data as needed
data-> x ++;
data-> y ++;
data-> z ++;
rcu.swap (data); // Check the return value can be useful
}
}


void reader_thread ()
{
while (true)
{
rcu.lock ();
std :: cost << rcu.get()->x << " n"; // read data
rcu.unlock ();
}
}

Questions: Does it make sense? Is it really thread-safe? Can a wire slip through the meshes of the hole somewhere?

Python: Declaring a Class in a Function to Encapsulate an Instantiation

I was wondering whether it is acceptable or bad to declare a class in a python function, which also supports proper instantiation of this class.

def get_access_token_provider ():

AuthTokenProvider class:
def __init __ (self, domain, client_id, client_secret):
self.domain = domain
self.client_id = client_id
self.client_secret = client_secret

def get_token (auto):
# this function uses a third-party library to retrieve a token and get it in the correct format

return AuthTokenProvider (config.get_auth_service_domain (), config.get_auth_client_id (), config.get_auth_client_secret ())


UsersManagement class:
def __init __ (auto):
self.domain = config.get_auth_service_domain
self.token_provider = get_access_token_provider ();

def add_user (auto, user):
# use token_provider here

The AuthTokenProvider class is not meant to be used anywhere other than in the current module.

Thank you for your opinion,
Cheers.

3.5nd dnd – How to replace an exploit that I have received as a class entity

Arcana unearthed sure Monk Variant: Combat Styles, in part, says

A monk may give up his fighting style by selecting an additional feat at the 2nd or 6th level. however, if she does, she loses the bonus on first level skill tests and never gains the combat style bonus ability (even if she encounters
prerequisites). (52)

In other words, at level 1, the monk could have avoided the feat of combat expertise by taking an additional feat of a combat style other than the passive method (such as Combat Attacking Attack Style which, at Level 1, confers the Power Attack bonus feat). Then, at level 2, the monk could have achieved the Improved Trip feat thanks to the Passive Way combat style. Anything that a multi-style monk gives up at level 2 is a +2 bonus on a specific skill. (The Passive Way combat style, for example, gives a +2 bonus to Bluff skill tests.)

The rule is a little buried, poorly formulated and easily overlooked. Explaining to the DM that you were not aware of the rule may be enough for the DM to allow you to modify the exploit without needing explanations in the game.


Note: This answer is not intended as a global solution to the broader issues raised by the issue, but rather as an effort to address the specific problem of the claimant.

google in class – Does the Facebook Social Learning group only support up to 5 units?

I have created a new Facebook group with the type of social learning group after reading about it here.

This is great for study groups and discussions, but it only supports 5 units maximum. You can still create more than 5 units, if you can not manage them (move up / down / up / down, edit or delete units).

Is there a way to manage units 6 and above?

If this is not possible, what is the best free online channel for a study / discussion group with the possibility of organizing its content. I've read about Google Classroom, but I have not explored it yet.

8 – How can I add a custom form to the output of a controller class?

I have a controller in my custom module. Inside this controller, I need to render a lot of different things (basic HTML code, multiple forms, etc.). My main problem is that I can not understand how

  1. Load a custom Drupal 8 form correctly
  2. Then, get this form in an acceptable format to pass it to the #markup output of the controller.
  3. Keep in mind that this form is mixed with other html that will be a mix of many things not shown here (I have reduced them to show a basic example)

My controller code looks like this right now:

<? php

Drupal namespace  my_module  Controller;
use Drupal  Core  Controller  ControllerBase;

SingleNodeProcessor class extends ControllerBase {

public function processSingle ($ nest) {
$ markup = & # 39;
& # 39 ;. $ this-> t (& # 39;) My custom form is below but there will be a lot more HTML than the form, so it's only an example. & # 39;
& # 39 ;; $ form = $ this-> formBuilder () -> getForm (Drupal my_module Form MyFormClassGoesHere, # $); $ markup. = $ form; // it's a rendering array, how can i convert it to html so that it can go to #markup? return [ '#type' => 'markup', '#markup' => $markup, ]; } }