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

  • SEARCH
  • Home
  • 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 8410205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:07:01+00:00 2026-06-10T00:07:01+00:00

Currently I have some code like this: OntologyGenerator generator = new OntologyGenerator(); generator.AddOntologyHeader(Testing); generator.AddClassDeclaration(owlBuilder);

  • 0

Currently I have some code like this:

    OntologyGenerator generator = new OntologyGenerator();
    generator.AddOntologyHeader("Testing");
    generator.AddClassDeclaration(owlBuilder);
    generator.AddSubClass(owlBuilder);
    generator.AddAnnotationAssertions(owlBuilder);

where that OwlBuilder param you see being passed has collections of objects like this:

public class OwlLBuilder: IOwlLBuilder
{
       private ICollection<IOwlClass> owlClasses = new Collection<IOwlClass>();
       private ICollection<IOwlRelation>  owlRelations = new Collection<IOwlRelation> ();
}

so for example when I say generator.AddClassDeclaration(owlBuilder); it will be looping through owlClasses collection of that owlBuilder param and do some stuff to it…

I feel it is an ugly design. Do you think I can take benefit of modifying my existing code to use Template Method Design Pattern or any other better design suggestions that you have? well with some code sample so I can have the big picture of what I should do in my head!

  • 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-06-10T00:07:02+00:00Added an answer on June 10, 2026 at 12:07 am

    I really can’t see Template Method in here. I see the Visitor pattern.

    Here’s an example.

    Imagine you’ve got a bunch of houses, and you need them all to be painted yellow. Now you could just:

    var houses = ... a list of houses ...
    
    foreach (var house in houses)
    {
        house.Color = Color.Yellow;
    }
    

    But instead of always painting your houses yellow, you may want the action (in this case painting) abstracted away into something else. One solution is to write a class that’s responsible for painting a house yellow. That class could later be substituted for another class that paints the house in a different color, or does something completely different with your house, like adding another floor!

    Enter the Visitor pattern.

    I’ll show some of the generic helper classes and interfaces I’ve been using. I like generics. If you don’t, feel free to roll your own. The semantics are: “a visitor visits a visitable”, and “a visitable accepts a visitor”.

    public interface IVisitor<in T> where T : IVisitable<T>
    {
        void Visit(T visitable);
    }
    
    public interface IVisitable<out T> where T : IVisitable<T>
    {
        void Accept(IVisitor<T> visitor);
    }
    
    public abstract class Visitable<T> : IVisitable<T> where T : Visitable<T>
    {
        public void Accept(IVisitor<T> visitor)
        {
            visitor.Visit((T)this);
        }
    }
    
    public abstract class VisitableList<T> : List<T>, IVisitable<T> where T : Visitable<T>
    {
        public void Accept(IVisitor<T> visitor)
        {
            foreach (var item in this)
            {
                item.Accept(visitor);
            }
        }
    }
    

    Now we can set up our house and our list of houses like this:

    public class House : Visitable<House>
    {
        public Color Color { get; set; }
    }
    
    public class Houses : VisitableList<House> {}
    

    And now, the visitor – our painter – who can visit our visitable house:

    public class YellowPainter : IVisitor<House>
    {
        public void Visit(House visitable)
        {
            visitable.Color = Color.Yellow;
        }
    }
    

    Simple, elegant and a single responsibility(!).

    Let’s set up the houses:

    var houses = new Houses();
    houses.Add(new House() { Color = Color.Green });
    houses.Add(new House() { Color = Color.Blue });
    houses.Add(new House() { Color = Color.White });
    

    Now we’re ready to paint all of our houses. It only takes one call:

    houses.Accept(new YellowPainter());
    

    …and all our houses are now yellow. Nice!

    We could just as easily do this:

    houses.Accept(new AdditionalFloorsBuilder(floors: 2));
    

    Or this:

    owlClasses.Accept(new OwlClassVisitor(owlBuilder, ...));
    

    By doing this, we’ve isolated what happens on the actual “visit” of each element in owlClasses, from the iteration of the collection itself. The visit needn’t modify the visitable. It could be used to only inspect the visitable and use the information to modify something completely different, eg. you could use the information to feed your owlBuilder.

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

Sidebar

Related Questions

Currently I have some code that looks like this void calc_run(Calculation *c, Input *i);
I have some code like this: Dim col As Collection = New Collection col.Add(value1,
I have some code that does something like this pseudocode: Use CURL to get
Currently I have some code to replace strings in a file that looks like
I've been trying to implement unit testing and currently have some code that does
Currently I have some code like (condensed and removed a bunch of error checking):
I have some very simple sample code like this: $.ajax({ url: 'demo2.htm', success: function(loadeddata){
I have some very simple sample code like this: $.ajax({ url: 'demo2.htm', success: function(loadeddata){
I have some code like this: var effects = xElement.Elements ( Effects ).Elements (
I currently have some code that looks like: -(UIView)someMethod { CGRectMake(0,0,100,100); UILabel *label =

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.