Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4333398
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:23:17+00:00 2026-05-21T10:23:17+00:00

Imagine I have a abstract FriendEvent model which has several different concrete implementations, ie.

  • 0

Imagine I have a abstract “FriendEvent” model which has several different concrete implementations, ie. FriendPosted, FriendCommented, FriendUploadedPhoto etc. They should all be rendered in my view of FriendEvents, but should be visually distinct from each other (e.g. FriendUploadPhoto should include a thumbnail).

What is a good object oriented pattern to achieve this?

I’m interested to learn if there’s an alternative to switching on the concrete class of the model in the view code. That somehow feels wrong because it uses conditional logic where I believe it should be possible to rely on polymorphism, but I have a hard time thinking up a better idea. Are there any established patterns to deal with this?

(I obviously don’t want to implement the view logic in the model, since that would be mixing the responsibilities, and since I may want to have different views for each model)

To clarify: How to model the different event type in the model layer is not the problem. There are several well known OO solutions. The question concerns the view code which is responsible for presenting the models visually. I imagine I have an EventView class which deals with showing an event (model). The question is: How to implement this class without a switch block that selects a different code path depending on the concrete type of Event is is rendering.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T10:23:18+00:00Added an answer on May 21, 2026 at 10:23 am

    Seems like you have some DoubleDispatch concerns going on here.

    If I understand you correctly, you are trying to avoid mixing Model and View. Each Event class could have

    HtmlString getHtmlView() { /* code */ }
    

    but then all events have view knowledge and each time we add a new kind of view we add a new getXXXView() method. I agree that this sees unpleasant.

    So we could increase the separation of concerns by having all events offer

    HtmlViewMaker getHtmlMaker {  return new MyKindOfViwer(this); }
    

    Now at least we’ve got the View code out into its own class. Yes we may well need to write special case code for each/many kinds of events, but that’s inevitable. Our first problem is where to put that special code – and that we’ve an answer for.

    However we still have a problem: each new kind of View needs a new getXxxMaker method. So we start to look at more complex Factories and the use of Generics and Templates and so on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have an function which goes through one million/billion strings and checks smth
Imagine I have a process that starts several child processes. The parent needs to
Imagine we have a program trying to write to a particular file, but failing.
Imagine I have String in C#: I Don’t see ya.. I want to remove
Imagine I have a chunk of initialisation code at the top of a stored
Imagine I have the folling XML file: <a>before<b>middle</b>after</a> I want to convert it into
Imagine I have these python lists: keys = ['name', 'age'] values = ['Monty', 42,
Imagine I have table like this: id:Product:shop_id 1:Basketball:41 2:Football:41 3:Rocket:45 4:Car:86 5:Plane:86 Now, this
Imagine I have a property defined in global.asax. public List<string> Roles { get {
Imagine I have the following: inFile = /adda/adas/sdas/hello.txt # that instruction give me hello.txt

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.