<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OOP &#8211; CS@Worcester</title>
	<atom:link href="https://cs.worcester.edu/category/oop/feed/" rel="self" type="application/rss+xml" />
	<link>https://cs.worcester.edu</link>
	<description>Worcester State University Computer Science Department</description>
	<lastBuildDate>Wed, 24 Dec 2025 03:34:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
<site xmlns="com-wordpress:feed-additions:1">236835116</site>	<item>
		<title>Introduction to Design Patterns</title>
		<link>https://bforbuild.dev/blog/introduction-to-design-patterns</link>
		
		<dc:creator><![CDATA[BforBuild]]></dc:creator>
		<pubDate>Wed, 24 Dec 2025 03:34:36 +0000</pubDate>
				<category><![CDATA[architecture]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Software Development]]></category>
		<guid isPermaLink="false">https://bforbuild.dev/blog/introduction-to-design-patterns</guid>

					<description><![CDATA[A comprehensive guide to design patterns in software development. Learn about creational, structural, and behavioral patterns with real-world examples and best practices.]]></description>
										<content:encoded><![CDATA[<div class="article-content">
<h2>What Are Design Patterns?</h2>
<p>Design patterns are proven, reusable solutions to common problems that arise in software design. They represent best practices evolved over time by experienced software developers. Rather than being finished code that you can copy and paste, design patterns are templates or blueprints that describe how to solve a problem in various situations.</p>
<p>Think of design patterns as the architectural blueprints of software development. Just as architects use established patterns for building structures (like how to design a doorway or window), software developers use design patterns to solve recurring design problems in a standardized way.</p>
<h2>Why Design Patterns Matter</h2>
<p>Design patterns offer several key benefits:</p>
<ul>
<li><strong>Reusability:</strong> Patterns provide solutions that have been tested and proven in real-world scenarios</li>
<li><strong>Communication:</strong> They create a common vocabulary for developers to discuss design solutions</li>
<li><strong>Best Practices:</strong> They encapsulate years of collective programming wisdom</li>
<li><strong>Maintainability:</strong> Code following patterns is typically easier to understand and modify</li>
<li><strong>Scalability:</strong> Patterns help structure code in ways that accommodate growth</li>
</ul>
<h2>The Three Categories of Design Patterns</h2>
<p>Design patterns are typically organized into three fundamental categories based on their purpose:</p>
<h3>1. Creational Patterns</h3>
<p>Creational patterns deal with object creation mechanisms, trying to create objects in a manner suitable to the situation. They help make a system independent of how its objects are created, composed, and represented.</p>
<h4>Common Creational Patterns:</h4>
<ul>
<li><strong>Factory Pattern:</strong> Creates objects without specifying the exact class of object that will be created</li>
<li><strong>Singleton Pattern:</strong> Ensures a class has only one instance and provides global access to it</li>
<li><strong>Builder Pattern:</strong> Constructs complex objects step by step</li>
<li><strong>Prototype Pattern:</strong> Creates new objects by copying existing ones</li>
<li><strong>Abstract Factory Pattern:</strong> Provides an interface for creating families of related objects</li>
</ul>
<h3>2. Structural Patterns</h3>
<p>Structural patterns explain how to assemble objects and classes into larger structures while keeping these structures flexible and efficient. They focus on how classes and objects are composed to form larger structures.</p>
<h4>Common Structural Patterns:</h4>
<ul>
<li><strong>Adapter Pattern:</strong> Allows incompatible interfaces to work together</li>
<li><strong>Decorator Pattern:</strong> Adds new functionality to objects dynamically</li>
<li><strong>Facade Pattern:</strong> Provides a simplified interface to a complex subsystem</li>
<li><strong>Proxy Pattern:</strong> Provides a placeholder or surrogate for another object</li>
<li><strong>Bridge Pattern:</strong> Separates an object&#8217;s interface from its implementation</li>
</ul>
<h3>3. Behavioral Patterns</h3>
<p>Behavioral patterns are concerned with algorithms and the assignment of responsibilities between objects. They describe not just patterns of objects or classes but also the patterns of communication between them.</p>
<h4>Common Behavioral Patterns:</h4>
<ul>
<li><strong>Observer Pattern:</strong> Defines a one-to-many dependency between objects</li>
<li><strong>Strategy Pattern:</strong> Defines a family of algorithms and makes them interchangeable</li>
<li><strong>Command Pattern:</strong> Encapsulates a request as an object</li>
<li><strong>State Pattern:</strong> Allows an object to alter its behavior when its internal state changes</li>
<li><strong>Template Method Pattern:</strong> Defines the skeleton of an algorithm in a method</li>
</ul>
<h2>Deep Dive: Key Design Patterns</h2>
<h3>The Singleton Pattern</h3>
<p>The Singleton pattern ensures that a class has only one instance and provides a global point of access to it. This is useful when exactly one object is needed to coordinate actions across the system.</p>
<p><strong>When to Use:</strong></p>
<ul>
<li>When you need exactly one instance of a class (database connections, logging, configuration)</li>
<li>When you need global access to that instance</li>
<li>When the instance should be lazy-initialized</li>
</ul>
<p><strong>Example Implementation:</strong></p>
<pre><code>class Database {
  private static instance: Database | null = null;
  
  private constructor() {
    // Private constructor prevents direct instantiation
  }
  
  public static getInstance(): Database {
    if (!Database.instance) {
      Database.instance = new Database();
    }
    return Database.instance;
  }
  
  public query(sql: string): void {
    console.log(`Executing: ${sql}`);
  }
}

// Usage
const db1 = Database.getInstance();
const db2 = Database.getInstance();
console.log(db1 === db2); // true - same instance</code></pre>
<p><strong>Considerations:</strong> While Singleton is useful, it can make testing difficult and can hide dependencies. Use it judiciously.</p>
<h3>The Factory Pattern</h3>
<p>The Factory pattern provides an interface for creating objects without specifying their exact classes. It encapsulates object creation and provides flexibility in deciding which class to instantiate.</p>
<p><strong>When to Use:</strong></p>
<ul>
<li>When you don&#8217;t know beforehand the exact types of objects your code will work with</li>
<li>When you want to provide a library of products and expose only their interfaces</li>
<li>When you want to extend your code to work with new types without modifying existing code</li>
</ul>
<p><strong>Example Implementation:</strong></p>
<pre><code>interface Animal {
  makeSound(): void;
}

class Dog implements Animal {
  makeSound(): void {
    console.log('Woof!');
  }
}

class Cat implements Animal {
  makeSound(): void {
    console.log('Meow!');
  }
}

class AnimalFactory {
  static createAnimal(type: string): Animal {
    switch (type) {
      case 'dog':
        return new Dog();
      case 'cat':
        return new Cat();
      default:
        throw new Error(`Unknown animal type: ${type}`);
    }
  }
}

// Usage
const dog = AnimalFactory.createAnimal('dog');
dog.makeSound(); // Woof!</code></pre>
<h3>The Observer Pattern</h3>
<p>The Observer pattern defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.</p>
<p><strong>When to Use:</strong></p>
<ul>
<li>When changes to one object require changing other objects, and you don&#8217;t know how many objects need to be changed</li>
<li>When an object should notify other objects without making assumptions about who those objects are</li>
<li>In event-driven systems, MVC architectures, and reactive programming</li>
</ul>
<p><strong>Example Implementation:</strong></p>
<pre><code>interface Observer {
  update(data: any): void;
}

class Subject {
  private observers: Observer[] = [];
  
  attach(observer: Observer): void {
    this.observers.push(observer);
  }
  
  notify(data: any): void {
    this.observers.forEach(observer => observer.update(data));
  }
}

class EmailObserver implements Observer {
  update(data: any): void {
    console.log(`Email sent: ${data}`);
  }
}

// Usage
const subject = new Subject();
subject.attach(new EmailObserver());
subject.notify('Order placed');</code></pre>
<h3>The Strategy Pattern</h3>
<p>The Strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. It lets the algorithm vary independently from clients that use it.</p>
<p><strong>When to Use:</strong></p>
<ul>
<li>When you have multiple ways to perform a task</li>
<li>When you want to avoid exposing complex, algorithm-specific data structures</li>
<li>When you want to switch algorithms at runtime</li>
</ul>
<p><strong>Example Implementation:</strong></p>
<pre><code>interface PaymentStrategy {
  pay(amount: number): void;
}

class CreditCardPayment implements PaymentStrategy {
  pay(amount: number): void {
    console.log(`Paid ${amount} using Credit Card`);
  }
}

class PayPalPayment implements PaymentStrategy {
  pay(amount: number): void {
    console.log(`Paid ${amount} using PayPal`);
  }
}

class PaymentProcessor {
  private strategy: PaymentStrategy;
  
  constructor(strategy: PaymentStrategy) {
    this.strategy = strategy;
  }
  
  setStrategy(strategy: PaymentStrategy): void {
    this.strategy = strategy;
  }
  
  processPayment(amount: number): void {
    this.strategy.pay(amount);
  }
}

// Usage
const processor = new PaymentProcessor(new CreditCardPayment());
processor.processPayment(100);
processor.setStrategy(new PayPalPayment());
processor.processPayment(200);</code></pre>
<h2>Design Patterns in Modern Development</h2>
<p>Many modern frameworks and libraries implement design patterns under the hood. Understanding these patterns helps you:</p>
<ul>
<li><strong>React:</strong> Uses Observer pattern for state management, Factory pattern for component creation</li>
<li><strong>Express.js:</strong> Uses Middleware pattern (a variant of Chain of Responsibility)</li>
<li><strong>Redux:</strong> Implements Observer pattern for state subscriptions</li>
<li><strong>Node.js EventEmitter:</strong> Classic implementation of Observer pattern</li>
</ul>
<h2>Common Pitfalls and Best Practices</h2>
<h3>Pitfalls to Avoid:</h3>
<ul>
<li><strong>Over-engineering:</strong> Don&#8217;t use patterns where simple code would suffice</li>
<li><strong>Pattern obsession:</strong> Not every problem needs a design pattern</li>
<li><strong>Misapplication:</strong> Using the wrong pattern for a problem</li>
<li><strong>Complexity:</strong> Some patterns add complexity—ensure the benefit outweighs the cost</li>
</ul>
<h3>Best Practices:</h3>
<ul>
<li><strong>Start Simple:</strong> Begin with straightforward code, refactor to patterns when needed</li>
<li><strong>Understand the Problem:</strong> Make sure you understand the problem before applying a pattern</li>
<li><strong>Know Your Patterns:</strong> Study the Gang of Four patterns and modern variations</li>
<li><strong>Practice:</strong> Implement patterns in your projects to gain experience</li>
<li><strong>Read Code:</strong> Study how popular frameworks use patterns</li>
</ul>
<h2>Learning Path for Design Patterns</h2>
<ol>
<li><strong>Start with the Basics:</strong> Understand Singleton, Factory, and Observer patterns</li>
<li><strong>Study Real Examples:</strong> Look at how patterns are used in popular frameworks</li>
<li><strong>Practice Implementation:</strong> Build small projects using different patterns</li>
<li><strong>Read the Gang of Four:</strong> Study the original &#8220;Design Patterns&#8221; book</li>
<li><strong>Explore Modern Patterns:</strong> Learn about patterns specific to your technology stack</li>
</ol>
<h2>Conclusion</h2>
<p>Design patterns are powerful tools in a developer&#8217;s arsenal, but they&#8217;re not silver bullets. They provide proven solutions to common problems and create a shared vocabulary for developers. However, the key is understanding when and how to apply them appropriately.</p>
<p>Remember: patterns should serve your code, not the other way around. Start with clear, simple code, and introduce patterns when they genuinely solve a problem or improve maintainability. As you gain experience, you&#8217;ll develop an intuition for when patterns are appropriate and when they&#8217;re overkill.</p>
<p>The journey to mastering design patterns is ongoing. Each pattern you learn adds another tool to your toolkit, making you a more versatile and effective developer. Keep practicing, keep learning, and most importantly, keep building.</p>
</p></div>

<p class="syndicated-attribution"><em>From the blog <a href="https://bforbuild.dev">BforBuild</a> by <a href="https://cs.worcester.edu/author/0/" title="Read other posts by BforBuild">BforBuild</a></em> and used with permission of the author. All other rights reserved by the author.</p>]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">50265</post-id>	</item>
		<item>
		<title>SW Design Strategy – Interfaces vs. Abstract Classes</title>
		<link>https://csworcester0.wordpress.com/2023/10/07/sw-design-strategy-interfaces-vs-abstract-classes/</link>
		
		<dc:creator><![CDATA[jelbirt]]></dc:creator>
		<pubDate>Sat, 07 Oct 2023 23:08:09 +0000</pubDate>
				<category><![CDATA[Abstract Class]]></category>
		<category><![CDATA[CS-343]]></category>
		<category><![CDATA[CS@Worcester]]></category>
		<category><![CDATA[Interface]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Week 4]]></category>
		<guid isPermaLink="false">http://csworcester0.wordpress.com/?p=18</guid>

					<description><![CDATA[An age-old discussion in the computer science and Object-Oriented Programming world is whether/when to implement interfaces or inherit through abstract classes. In these first few weeks of CS-343 we’ve been working on several activities discussing some of the strengths, weaknesses, and differences between interfaces and abstract classes. In the past I’ve worked on some mid-modest […]]]></description>
										<content:encoded><![CDATA[<p>An age-old discussion in the computer science and Object-Oriented Programming world is whether/when to implement interfaces or inherit through abstract classes. In these first few weeks of CS-343 we’ve been working on several activities discussing some of the strengths, weaknesses, and differences between interfaces and abstract classes. In the past I’ve worked on some mid-modest sized projects which include both and can think of a few great examples of using each, but I found that I still struggled to understand some of the basic conceptual differences. So while I had a solid grasp on some effective use cases, I didn’t have a very clear idea on how to choose one/the other when in design stages where a lot less may be known about the project and how it may take shape later on.</p>
<p><em>Interfaces or Abstract Classes</em> is a blog post from 2017 that I came across through web searching which explains some of the key conceptual and strategic differences between abstract classes and interfaces. Author Suhas Chatekar begins by discussing some of the most common responses he has received when asking this question in interviews. Abstract classes are typically preferred if there are suspected to be changes/additions needed later on. Interfaces are considered best when there are likely to be many different definitions for the same inherited methods, or as a possible alternative or substitute in multiple-inheritance in languages which do not support it (like Java/C#).&nbsp;</p>
<p>Often it’s difficult to verbalize these differences, but this pretty well summarized my understanding. However, these philosophies focus on using interfaces to get around a syntax/language obstacle rather than as a best-case tool and are what Chatekar dubs “futuristic”, in that they rely on a programmer to <em>know</em> how the program is going to turn out longer term at the beginning which is simply unrealistic on a large scale project. Instead, he suggests an approach of considering interfaces as establishing a “can-do” relationship versus abstract classes creating a “is-a” relationship.</p>
<p>In the past and in CS-343, I’ve heard these terms thrown around and attached sometimes, but this post helped me to better understand the value in this approach and line of thinking for project planning. Commonly project components and requirements shift over the course of a project as unexpected needs are identified and addressed which cannot necessarily be planned for, so a futuristic interface-versus-abstract decision process seems likely to fail or be significantly less effective than a simplified approach focused on anticipated “is-a” and “can-do” relationships. One of my first and favorite interface/inheritance example projects simulated a Chess game using Java with a ChessPiece abstract class as well as a PieceAction interface; Regardless of later complications, each piece “is-a” ChessPiece, and “can-do” all PieceAction’s. This approach helps plan for future project events and needs in a more present state of mind, especially in long term projects that may include both.</p>
<p>Source:</p>
<p><a href="https://medium.com/@suhas_chatekar/interfaces-or-abstract-classes-bce12dce97e">Interfaces or Abstract Classes?. I have been asking this question in… | by Suhas Chatekar | Medium</a></p></p>

<p class="syndicated-attribution"><em>From the blog <a href="https://csworcester0.wordpress.com">CS@Worcester – Tech. Worth Talking About</a> by <a href="https://cs.worcester.edu/author/0/" title="Read other posts by jelbirt">jelbirt</a></em> and used with permission of the author. All other rights reserved by the author.</p>]]></content:encoded>
					
		
		<enclosure url="https://0.gravatar.com/avatar/3189cd95b312f2153b40f34596d8f1b6ffc5be289659b203a950879967a0be83?s=96&#038;d=identicon&#038;r=G" length="0" type="" />

		<post-id xmlns="com-wordpress:feed-additions:1">19704</post-id>	</item>
		<item>
		<title>The Insatiable Quest for Prime Numbers</title>
		<link>https://theintrospectivethinker529047368.wordpress.com/2020/11/15/the-insatiable-quest-for-prime-numbers/</link>
		
		<dc:creator><![CDATA[David MacDonald]]></dc:creator>
		<pubDate>Sun, 15 Nov 2020 18:38:31 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Computers]]></category>
		<category><![CDATA[CS-343]]></category>
		<category><![CDATA[CS@Worcester]]></category>
		<category><![CDATA[Discussions]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[Number Theory]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Primes]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[Week 10]]></category>
		<guid isPermaLink="false">http://theintrospectivethinker529047368.wordpress.com/?p=106</guid>

					<description><![CDATA[I have been coding at least since 2013. I started off self taught and now I’m majoring in CS, while still constantly learning outside of classes. I went from language to language, but something that almost always followed me was…  <p class="more-link"><a href="https://theintrospectivethinker529047368.wordpress.com/2020/11/15/the-insatiable-quest-for-prime-numbers/">Continue reading <span class="meta-nav">→</span></a></p>]]></description>
										<content:encoded><![CDATA[<p>I have been coding at least since 2013. I started off self taught and now I&#8217;m majoring in CS, while still constantly learning outside of classes. I went from language to language, but something that almost always followed me was the idea of a prime number generator.</p>
<p>I must&#8217;ve tried this in almost every language I&#8217;ve used. It&#8217;s a very simple idea: create a console based program that can both check if an integer is prime, and print out a list of primes in order as quickly as possible. Usually, I don&#8217;t get too far for reasons I&#8217;ll get into. Although, I did succeed mostly with C++. I had an incredibly quick program (once I realized how terribly slow it was to print out the results to the screen) that ran on multiple threads and could fill up a file with prime numbers. I had two main problems: the file it filled up became so big that notepad wouldn&#8217;t be able to open it and the max size of an unsigned long. </p>
<p>Looking back at that code, it was a horrible mess and I&#8217;ve come a long way in both C++ and general code design. However, ever since then my quest began to create a data structure from scratch that could allow me to handle enormous primes. I managed to create a class that used strings to hold values. I defined all necessary arithmetic operations and it worked. <strong>Incredibly slowly.</strong> I should also mention that while I&#8217;m constantly coming back to this idea, my attention wanes as I run out of time between vacations.</p>
<p>Using strings was a horrible idea. Not only are they really slow when you try to treat them like numbers, but they are a huge waste of memory. Each character is 1 byte and in base 10 I would only be using 10 values per character. Even using base Z (where I use 0-9 and then a-z and finally A-Z), it would be a very stupid waste of space. So I started thinking about how I could store numbers more efficiently. In C++, it really isn&#8217;t that hard.</p>
<p>The solution I came up with involved std::size_t&#8217;s (size_t). It&#8217;s just a compiler name for the largest possible unsigned integer. Since I have a decent background in number bases (see my blog post on <a href="https://theintrospectivethinker529047368.wordpress.com/2020/09/07/introduction-to-the-duodecimal-system/">Duodecimal</a> and why we should all switch to it), I was inspired. My design was a linked list structure of size_t&#8217;s. I used a linked list rather than an array because I wanted &#8220;small&#8221; numbers to not take up a lot of space, I wanted to avoid reallocation, and I also wanted to prevent an upper limit for the size. In theory, this object can be as large as memory allows. If I used something like a std::vector, it&#8217;s size itself is stored as a size_t. </p>
<p>Each size_t is the largest possible integer in C++. And each node in the linked list acts like a digit of a base. Let n be the largest size_t number. Suppose you have n + 1. That number would basically just be 1&lt;&#8212;&gt;0 in this form. Then you keep ticking up the 1&#8217;s digit, etc. This means that the numbers are stored incredibly densely.  We&#8217;re dealing with base (n+1). In my case, I think n is 64 bits. So n=2<sup>64</sup> &#8211; 1.  Anyway, to store n<sup>2</sup> , you would need 2 nodes. To store n<sup>k</sup> you only need 64*k bits. </p>
<p>This is insanely better than using strings. Since they&#8217;re integers already as well, I get to avoid conversion. My problem recently has been finding the time and motivation to work on this. I try to create unit tests so I can guarantee it&#8217;s working as expected and I get bored. I also need to find efficient algorithms for arithmetic operations. </p>
<p>Despite my inability to complete this project, it does a good job of showing the benefits of Object Oriented Programming. I can take all of this complexity and shove it into a class. Once that class is done, I can create the functions to simply calculate primes the normal way. </p>
<h2>Checking Primality</h2>
<p>The most basic way to check if an integer is prime is to check if any positive integers less than it (other than 1) divide it. From there, you might realize that you can skip all of the even numbers after 2 because if 2 doesn&#8217;t divide it, then neither will any of the evens. Then you can also skip all integers larger than it&#8217;s square root as factors come in pairs. A few proofs would easily show these results to be true. Then you can continue to progress downwards. However, I&#8217;ve come up with a method as well.</p>
<p>How come after you check 2 you can skip all of the even numbers? Okay I suppose I should do one simple proof here:</p>
<figure class="wp-block-image size-large"><img data-recalc-dims="1" decoding="async" data-attachment-id="118" data-permalink="https://theintrospectivethinker529047368.wordpress.com/image/" data-orig-file="https://theintrospectivethinker529047368.files.wordpress.com/2020/11/image.png" data-orig-size="667,187" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="image" data-image-description="" data-medium-file="https://theintrospectivethinker529047368.files.wordpress.com/2020/11/image.png?w=300" data-large-file="https://theintrospectivethinker529047368.files.wordpress.com/2020/11/image.png?w=636" src="https://theintrospectivethinker529047368.files.wordpress.com/2020/11/image.png?w=625" alt="" class="wp-image-118" srcset="https://theintrospectivethinker529047368.files.wordpress.com/2020/11/image.png 667w, https://theintrospectivethinker529047368.files.wordpress.com/2020/11/image.png?w=150 150w, https://theintrospectivethinker529047368.files.wordpress.com/2020/11/image.png?w=300 300w" sizes="(max-width: 667px) 100vw, 667px" /></figure>
<p>In fact, let me do this in general: </p>
<figure class="wp-block-image size-large"><img data-recalc-dims="1" decoding="async" data-attachment-id="120" data-permalink="https://theintrospectivethinker529047368.wordpress.com/image-1/" data-orig-file="https://theintrospectivethinker529047368.files.wordpress.com/2020/11/image-1.png" data-orig-size="694,188" data-comments-opened="1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" data-image-title="image-1" data-image-description="" data-medium-file="https://theintrospectivethinker529047368.files.wordpress.com/2020/11/image-1.png?w=300" data-large-file="https://theintrospectivethinker529047368.files.wordpress.com/2020/11/image-1.png?w=636" src="https://theintrospectivethinker529047368.files.wordpress.com/2020/11/image-1.png?w=625" alt="" class="wp-image-120" srcset="https://theintrospectivethinker529047368.files.wordpress.com/2020/11/image-1.png 694w, https://theintrospectivethinker529047368.files.wordpress.com/2020/11/image-1.png?w=150 150w, https://theintrospectivethinker529047368.files.wordpress.com/2020/11/image-1.png?w=300 300w" sizes="(max-width: 694px) 100vw, 694px" /></figure>
<p>I enjoy a nice simple proof every now and then, even though I could&#8217;ve just cited transitivity of divides. Anyway, what this is telling us is that this applies for any factors. Any time an integer does not divide our potential prime, we can ignore <strong>all</strong> multiples. </p>
<p>What I&#8217;m getting at is that the hypothetically most efficient method for verifying primality is to check all primes up to it&#8217;s square root. Since every number is either prime or the multiple of primes, checking a prime also checks every single multiple of that prime. The problem is that you need a list of primes to check. Hence, my program would store primes and use them to verify if a number is a prime. </p>
<p>You may be thinking that if I have a list of primes, why bother at all with arithmetic. And thinking about it, having an &#8220;exhaustive&#8221; list of primes (an exhaustive infinite list&#8230;) and simply checking that list could be very efficient to verify a number is prime. However it would be pretty inefficient to verify that the average number is <strong>not</strong> prime. The reason I&#8217;m not using that method is because my list of primes is small and slowly grows. I only need to store primes up to the square root recall. That means to check 100, I&#8217;ll only have 2,3,5, and 7 stored. To check 10,000, I&#8217;ll only have all 2 digit primes. </p>
<p>So as I verify primes the list would grow and add more factors in order. You would also want to check the smaller primes first. While you can&#8217;t exactly say that more integers are even than are multiples of 5 due to the set being infinite, any complete finite subset of consecutive integers has this property. Multiples of 2 will make up half of the elements, multiples of 3 one third, etc. So you&#8217;ll want to start with the smaller primes first. </p>
<p>How to determine divisibility is also up to you. For instance, in base 10 we can rule out any integer who&#8217;s first digit is a 0 or 5 (except the number 5 itself) since that rules out multiples of 5 and 10. However, when working with duodecimal, I realized different number bases have different properties for divisibility. For example, in base 12 every multiple of 4 and 8 ends in 0,4, or 8. Every multiple of 3 and 9 ends in 0,3,6, or 9. Every multiple of 6 ends in 0 or 6. Every multiple of 12 ends in 0. </p>
<p>You could potentially have an algorithm to convert the integer to a different number base that is more efficient than performing an arithmetic calculation. Especially considering that for these tricks, you only need to convert the first few digits of the number. I think it&#8217;s a really interesting idea, however you risk circumventing the benefits of the machine code. Often times you try to make something more efficient, and then it&#8217;s either unnecessary or makes performance worse because the compiler was able to do a better job &#8220;fixing&#8221; your code. I think either way I&#8217;ll have to experiment with these idea in the future. Thinking about it, you only need to convert the number to the base of the prime and then check if the 1s digit is 0. You can then modify how many digits you actually convert based on how many digits the base-prime number will be. For larger numbers this might have potential. </p>
<h2>Conclusion</h2>
<p>While this project may not be the best example, I think it&#8217;s very useful for programmers to have a &#8220;go to&#8221; project for practicing an unfamiliar  language. Something simple enough to allow you to write it from memory, while complex enough to give you a good grasp of the language. In this primes project, I have to handle the terminal, arithmetic, functions, objects, files, threads, etc. If I simplified it down and ignored my ambitions, it would server as a very functional example to allow you to learn the syntax and libraries of a new language. Ideally, you wouldn&#8217;t even have the original code to look at. You would just program the functionality from memory using your IDE and Google to figure out syntax. The best way to learn a language is to use it. If you have something familiar in your mind, then you have a great example project to work on already. I find struggling to implement functionality and spending a lot of time searching for a solution has taught me an invaluable amount about the languages I use.</p>

<p class="syndicated-attribution"><em>From the blog <a href="https://theintrospectivethinker529047368.wordpress.com">CS@Worcester – The Introspective Thinker</a> by <a href="https://cs.worcester.edu/author/0/" title="Read other posts by David MacDonald">David MacDonald</a></em> and used with permission of the author. All other rights reserved by the author.</p>]]></content:encoded>
					
		
		<enclosure url="https://2.gravatar.com/avatar/8673d52cf7b1c89e4cc8d888be204ba4?s=96&#038;d=identicon&#038;r=G" length="0" type="" />
<enclosure url="https://theintrospectivethinker529047368.files.wordpress.com/2020/11/image.png?w=667" length="0" type="" />
<enclosure url="https://theintrospectivethinker529047368.files.wordpress.com/2020/11/image-1.png?w=694" length="0" type="" />

		<post-id xmlns="com-wordpress:feed-additions:1">14505</post-id>	</item>
		<item>
		<title>Hello fellow CS enthusiasts and beginner programmers!</title>
		<link>https://jsimolaris.wordpress.com/2020/09/19/hello-fellow-cs-enthusiasts-and-beginner-programmers/</link>
		
		<dc:creator><![CDATA[jsimolaris]]></dc:creator>
		<pubDate>Sun, 20 Sep 2020 02:39:56 +0000</pubDate>
				<category><![CDATA[CS-343]]></category>
		<category><![CDATA[CS@Worcester]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Week-2]]></category>
		<guid isPermaLink="false">http://jsimolaris.wordpress.com/?p=75</guid>

					<description><![CDATA[  In this week’s blog post, I plan to go over Object Oriented Programming. I found an excellent blog that explains the four principles of OOP; encapsulation, abstraction, inheritance and polymorphism. The author hilariously titled the blog “How to explain object-oriented programming concepts to a 6-year-old”. As a father of two 6 year old boys,<a class="more-link" href="https://jsimolaris.wordpress.com/2020/09/19/hello-fellow-cs-enthusiasts-and-beginner-programmers/">Continue reading <span class="screen-reader-text">"Hello fellow CS enthusiasts and beginner programmers!"</span></a>]]></description>
										<content:encoded><![CDATA[</p>
<p>  In this week’s blog post, I plan to go over Object Oriented Programming. I found an excellent <a rel="noreferrer noopener" href="https://www.freecodecamp.org/news/object-oriented-programming-concepts-21bb035f7260/" >blog</a> that explains the four principles of OOP; encapsulation, abstraction, inheritance and polymorphism. The author hilariously titled the blog “How to explain object-oriented programming concepts to a 6-year-old”. As a father of <span style="text-decoration:underline;">two</span> 6 year old boys, I don’t see many 6 year old’s understanding it but it did however clarify Object Oriented Programming for me. I chose this specific blog because I found it comprehensible and uncomplicated. It was written and formatted in a way that made it very enjoyable to read. I have read many examples in textbooks but none of them were as easy to understand as these for me.</p>
</p>
<p>   I enjoyed the simple example the blogger used to explain encapsulation. Encapsulation happens when the object keeps its state private inside a class, but other objects can’t directly access it. Other objects they can only use public methods. The object maintains its own state, and unless explicitly stated other classes can’t change it. We are made aware of a developing sim game involving a cat class which has private variables as the “state” of the cat such as mood, hungerLevel, energyLevel. The cat in the example also has a private meow() method, and public methods sleep(), play() and feed(). Each of the public methods modifies the state of the cat class and has the possibility of invoking the private meow() method.</p>
<p>   To explain abstraction, the blogger used an example of a cellphone. When using your cellphone, you only need to use a few buttons because implementation details are hidden. We don’t need to be aware of all the intricate processes that occur when we press buttons on our cellphones, we just need them to behave accordingly as expected.</p>
<p>   Inheritance is the concept of code being reused to create more specific types of an object. is fairly easy to understand due to classes being referred to as parent and child classes. The child receives all the fields and methods of the parent class but can also have its own unique methods and fields.</p>
<p>   When explaining polymorphism, the author uses the example of a parent “shape” class with the children triangle, circle, and rectangle. In the shape class we have methods CalculateSurfaceArea(), and CalculatePerimeter(). The children classes utilize polymorphism when calling the abstract classes of the parent because they each have their own formulas for surface area and perimeter.</p>
<p>Since discovering this blog post, I am more confident in my understanding of OOP. I can visualize the 4 principles better and will be able to utilize them in my coding much more efficiently now. I hope you enjoyed this blog post, attached below is the blog which inspired my post.</p>
<p><a href="https://www.freecodecamp.org/news/object-oriented-programming-concepts-21bb035f7260/" rel="nofollow">https://www.freecodecamp.org/news/object-oriented-programming-concepts-21bb035f7260/</a></p>

<p class="syndicated-attribution"><em>From the blog <a href="https://jsimolaris.wordpress.com">cs@worcester – Coding_Kitchen</a> by <a href="https://cs.worcester.edu/author/0/" title="Read other posts by jsimolaris">jsimolaris</a></em> and used with permission of the author. All other rights reserved by the author.</p>]]></content:encoded>
					
		
		<enclosure url="https://2.gravatar.com/avatar/5d0e64291f728a32aff338ab4cbbf946?s=96&#038;d=identicon&#038;r=G" length="0" type="" />

		<post-id xmlns="com-wordpress:feed-additions:1">14384</post-id>	</item>
	</channel>
</rss>
