<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ufere Samuel on Medium]]></title>
        <description><![CDATA[Stories by Ufere Samuel on Medium]]></description>
        <link>https://medium.com/@uferesamuel?source=rss-a688fa2cf1f7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*j-IrO6qKbJHiAGOyIyXYig.jpeg</url>
            <title>Stories by Ufere Samuel on Medium</title>
            <link>https://medium.com/@uferesamuel?source=rss-a688fa2cf1f7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 04:24:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@uferesamuel/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Understanding Android Architecture]]></title>
            <link>https://medium.com/@uferesamuel/understanding-android-architecture-6d3a1f9fd473?source=rss-a688fa2cf1f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d3a1f9fd473</guid>
            <dc:creator><![CDATA[Ufere Samuel]]></dc:creator>
            <pubDate>Tue, 12 May 2020 10:57:11 GMT</pubDate>
            <atom:updated>2020-05-12T15:10:38.093Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KiXFMm_IWYHZG2Fi.png" /></figure><p>Hello guys, one of the issues i had early as an upcoming developer was understanding the <strong><em>CONCEPT OF ANDROID ARCHITECTURE.</em></strong></p><p>I’m writing this article because with my years of experience developing android applications using Java/Kotlin, i lost a lucrative opportunity to work with a multinational company as a Lead Android Developer simply because i had been too busy writing codes without taking out time to understand the various Architectures there is to android development even though i was working with them.</p><p>Self taught developers will agree with me that our concerns is more on workability than all the “Jargons” associated with it. I understood the hard way that <em>as good as understanding the practicals is, the theory is equally important.</em></p><p>Ok…. enough of stories, lets dive into the business of the day.</p><h3>What is Android Architecture?</h3><p>Android architecture is the way you structure your Android project code so that your code is scalable and easy to maintain. Developers spend more time maintaining a project than initially building it, so it makes sense to follow a proper architectural pattern.</p><h3>Examples of Android Architecture</h3><ol><li>MVC (Model-View-Controller)</li><li>MVP (Model-View-Presentation)</li><li>MVVM (Model-View-ViewModel)</li></ol><h3>What is the difference between MVC and MVVM?</h3><p>In Android, MVC refers to the default pattern where an Activity acts as a controller and XML files are views. MVVM treats both Activity classes and XML files as views, and ViewModel classes are where you write your business logic. It completely separates an app’s UI from its logic.</p><h3>What is the difference between MVP and MVVM?</h3><p>In MVP, the presenter knows about the view and view knows about the presenter. They interact with each other through an interface. In MVVM, only the view knows about the view-model. The view-model has no idea about the view.</p><h3>What are the key components of Android Architecture?</h3><p>One is separation of concerns, i.e. your business logic, UI, and data models should live at different places. Another is the decoupling of code: Every piece of code should act as a black box so that changing anything in a class should not have any effect on another part of your codebase.</p><h3>What is Clean Architecture?</h3><p>Robert C. Martin’s “Clean Architecture” is a pattern that lets you break down your interaction with data into simpler entities called “use cases.” It is great for writing decoupled code.</p><h3>What are Android repositories?</h3><p>Most apps save and retrieve data, either from local storage or a remote server. Android repositories are classes that decide whether data should come from a server or local storage, decoupling your storage logic from outside classes.</p><h3>Let’s dive deeper</h3><p>If you don’t choose the right architecture for your Android project, you will have a hard time maintaining it as your codebase grows and your team expands.</p><p>This isn’t just an Android MVVM tutorial. In this article, we are going to combine MVVM (Model-View-ViewModel or sometimes stylized “the ViewModel pattern”) with <a href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html">Clean Architecture</a>. We are going to see how this architecture can be used to write decoupled, testable, and maintainable code.</p><h3>Why MVVM with Clean Architecture?</h3><p>MVVM separates your view (i.e. Activitys and Fragments) from your business logic. MVVM is enough for small projects, but when your codebase becomes huge, your ViewModels start bloating. Separating responsibilities becomes hard.</p><p>MVVM with Clean Architecture is pretty good in such cases. It goes one step further in separating the responsibilities of your code base. It clearly abstracts the logic of the actions that can be performed in your app.</p><p>Note: You can combine Clean Architecture with the model-view-presenter (MVP) architecture as well. But since <a href="https://developer.android.com/topic/libraries/architecture/">Android Architecture Components</a> already provides a built-in ViewModel class, we are going with MVVM over MVP—no MVVM framework required!</p><h3>Advantages of Using Clean Architecture</h3><ul><li>Your code is even more easily testable than with plain MVVM.</li><li>Your code is further decoupled (the biggest advantage.)</li><li>The package structure is even easier to navigate.</li><li>The project is even easier to maintain.</li><li>Your team can add new features even more quickly.</li></ul><h3>Disadvantages of Clean Architecture</h3><ul><li>It has a slightly steep learning curve. How all the layers work together may take some time to understand, especially if you are coming from patterns like simple MVVM or MVP.</li><li>It adds a lot of extra classes, so it’s not ideal for low-complexity projects.</li></ul><p>Our data flow will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l1l0vbRnO92tQG8N.png" /><figcaption>Source: <a href="https://uploads.toptal.io/blog/image/127608/toptal-blog-image-1543413671794-80993a19fea97477524763c908b50a7a.png">https://uploads.toptal.io/blog/image/127608/toptal-blog-image-1543413671794-80993a19fea97477524763c908b50a7a.png</a></figcaption></figure><p>Our business logic is completely separated from our UI. It makes our code very easy to maintain and test.</p><p>The example we are going to see is quite simple. It allows users to create new posts and see a list of posts created by them. I’m not using any third-party library (like Dagger, RxJava, etc.) in this example for the sake of simplicity.</p><h3>The Layers of MVVM with Clean Architecture</h3><p>The code is divided into three separate layers:</p><ol><li>Presentation Layer</li><li>Domain Layer</li><li>Data Layer</li></ol><p>We’ll get into more detail about each layer below. For now, our resulting package structure looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tOO3LTiXKIY48jdheEQYVQ.png" /></figure><p>Even within the Android app architecture we’re using, there are many ways to structure your file/folder hierarchy. I like to group project files based on features. I find it neat and concise. You are free to choose whatever project structure suits you.</p><h3>The Presentation Layer</h3><p>This includes our Activitys, Fragments, and ViewModels. <strong>An </strong>Activity<strong> should be as dumb as possible. Never put your business logic in </strong>Activity<strong>s.</strong></p><p>An Activity will talk to a ViewModel and a ViewModel will talk to the domain layer to perform actions. A ViewModel never talks to the data layer directly.</p><p>Here we are passing a UseCaseHandler and two UseCases to our ViewModel. We’ll get into that in more detail soon, but in this architecture, a UseCase is an action that defines how a ViewModel interacts with the data layer.</p><p>Here’s how our Kotlin code looks:</p><pre><strong>class</strong> <strong>PostListViewModel</strong>(<br>        <strong>val</strong> useCaseHandler: UseCaseHandler,<br>        <strong>val</strong> getPosts: GetPosts,<br>        <strong>val</strong> savePost: SavePost): ViewModel() {<br><br><br>    <strong>fun</strong> <strong>getAllPosts</strong>(userId: <strong>Int</strong>, callback: <strong>PostDataSource</strong>.<strong>LoadPostsCallback</strong>) {<br>        <strong>val</strong> requestValue = GetPosts.RequestValues(userId)<br>        useCaseHandler.execute(getPosts, requestValue, <strong>object</strong> :<br>        UseCase.UseCaseCallback&lt;GetPosts.ResponseValue&gt; {<br>            <strong>override</strong> <strong>fun</strong> <strong>onSuccess</strong>(response: <strong>GetPosts</strong>.<strong>ResponseValue</strong>) {<br>                callback.onPostsLoaded(response.posts)<br>            }<br><br>            <strong>override</strong> <strong>fun</strong> <strong>onError</strong>(t: <strong>Throwable</strong>) {<br>                callback.onError(t)<br>            }<br>        })<br>    }<br><br>    <strong>fun</strong> <strong>savePost</strong>(post: <strong>Post</strong>, callback: <strong>PostDataSource</strong>.<strong>SaveTaskCallback</strong>) {<br>        <strong>val</strong> requestValues = SavePost.RequestValues(post)<br>        useCaseHandler.execute(savePost, requestValues, <strong>object</strong> :<br>        UseCase.UseCaseCallback&lt;SavePost.ResponseValue&gt; {<br>            <strong>override</strong> <strong>fun</strong> <strong>onSuccess</strong>(response: <strong>SavePost</strong>.<strong>ResponseValue</strong>) {<br>                callback.onSaveSuccess()<br>            }<br>            <strong>override</strong> <strong>fun</strong> <strong>onError</strong>(t: <strong>Throwable</strong>) {<br>                callback.onError(t)<br>            }<br>        })<br>    }<br><br>}</pre><h3>The Domain Layer</h3><p>The domain layer contains all the <strong>use cases</strong> of your application. In this example, we have UseCase, an abstract class. All our UseCases will extend this class.</p><pre><strong>abstract</strong> <strong>class</strong> <strong>UseCase</strong>&lt;<strong>Q : UseCase.RequestValues, P : UseCase.ResponseValue</strong>&gt; {<br><br>    <strong>var</strong> requestValues: Q? = null<br><br>    <strong>var</strong> useCaseCallback: UseCaseCallback&lt;P&gt;? = null<br><br>    <strong>internal</strong> <strong>fun</strong> <strong>run</strong>() {<br>        executeUseCase(requestValues)<br>    }<br><br>    <strong>protected</strong> <strong>abstract</strong> <strong>fun</strong> <strong>executeUseCase</strong>(requestValues: <strong>Q</strong>?)<br><br>    <em>/**<br>     * Data passed to a request.<br>     */</em><br>    <strong>interface</strong> <strong>RequestValues</strong><br><br>    <em>/**<br>     * Data received from a request.<br>     */</em><br>    <strong>interface</strong> <strong>ResponseValue</strong><br><br>    <strong>interface</strong> <strong>UseCaseCallback</strong>&lt;<strong>R</strong>&gt; {<br>        <strong>fun</strong> <strong>onSuccess</strong>(response: <strong>R</strong>)<br>        <strong>fun</strong> <strong>onError</strong>(t: <strong>Throwable</strong>)<br>    }<br>}</pre><p>And UseCaseHandler handles execution of a UseCase. We should never block the UI when we fetch data from the database or our remote server. This is the place where we decide to execute our UseCase on a background thread and receive the response on the main thread.</p><pre><strong>class</strong> <strong>UseCaseHandler</strong>(<strong>private</strong> <strong>val</strong> mUseCaseScheduler: UseCaseScheduler) {</pre><pre>    <strong>fun</strong> <strong>&lt;T : UseCase.RequestValues, R : UseCase.ResponseValue&gt;</strong> <strong>execute</strong>(<br>            useCase: <strong>UseCase</strong>&lt;<strong>T</strong>, R&gt;, values: <strong>T</strong>, callback: <strong>UseCase</strong>.<strong>UseCaseCallback</strong>&lt;<strong>R</strong>&gt;) {<br>        useCase.requestValues = values<br>        useCase.useCaseCallback = UiCallbackWrapper(callback, <strong>this</strong>)</pre><pre>        mUseCaseScheduler.execute(Runnable {<br>            useCase.run()<br>        })<br>    }</pre><pre>    <strong>private</strong> <strong>fun</strong> <strong>&lt;V : UseCase.ResponseValue&gt;</strong> <strong>notifyResponse</strong>(response: <strong>V</strong>,<br>                                                   useCaseCallback: <strong>UseCase</strong>.<strong>UseCaseCallback</strong>&lt;<strong>V</strong>&gt;) {<br>        mUseCaseScheduler.notifyResponse(response, useCaseCallback)<br>    }</pre><pre>    <strong>private</strong> <strong>fun</strong> <strong>&lt;V : UseCase.ResponseValue&gt;</strong> <strong>notifyError</strong>(<br>            useCaseCallback: <strong>UseCase</strong>.<strong>UseCaseCallback</strong>&lt;<strong>V</strong>&gt;, t: <strong>Throwable</strong>) {<br>        mUseCaseScheduler.onError(useCaseCallback, t)<br>    }</pre><pre>    <strong>private</strong> <strong>class</strong> <strong>UiCallbackWrapper</strong>&lt;<strong>V : UseCase.ResponseValue</strong>&gt;(<br>    <strong>private</strong> <strong>val</strong> mCallback: UseCase.UseCaseCallback&lt;V&gt;,<br>    <strong>private</strong> <strong>val</strong> mUseCaseHandler: UseCaseHandler) : UseCase.UseCaseCallback&lt;V&gt; {</pre><pre>        <strong>override</strong> <strong>fun</strong> <strong>onSuccess</strong>(response: <strong>V</strong>) {<br>            mUseCaseHandler.notifyResponse(response, mCallback)<br>        }</pre><pre>        <strong>override</strong> <strong>fun</strong> <strong>onError</strong>(t: <strong>Throwable</strong>) {<br>            mUseCaseHandler.notifyError(mCallback, t)<br>        }<br>    }</pre><pre>    <strong>companion</strong> <strong>object</strong> {</pre><pre>        <strong>private</strong> <strong>var</strong> INSTANCE: UseCaseHandler? = null<br>        <strong>fun</strong> <strong>getInstance</strong>(): UseCaseHandler {<br>            <strong>if</strong> (INSTANCE == null) {<br>                INSTANCE = UseCaseHandler(UseCaseThreadPoolScheduler())<br>            }<br>            <strong>return</strong> INSTANCE!!<br>        }<br>    }<br>}</pre><p>As its name implies, the GetPosts UseCase is responsible for getting all posts of a user.</p><pre><strong>class</strong> <strong>GetPosts</strong>(<strong>private</strong> <strong>val</strong> mDataSource: PostDataSource) :<br>UseCase&lt;GetPosts.RequestValues, GetPosts.ResponseValue&gt;() {</pre><pre>    <strong>protected</strong> <strong>override</strong> <strong>fun</strong> <strong>executeUseCase</strong>(requestValues: <strong>GetPosts</strong>.<strong>RequestValues</strong>?) {<br>        mDataSource.getPosts(requestValues?.userId ?: -1, <strong>object</strong> :<br>        PostDataSource.LoadPostsCallback {<br>            <strong>override</strong> <strong>fun</strong> <strong>onPostsLoaded</strong>(posts: <strong>List</strong>&lt;<strong>Post</strong>&gt;) {<br>                <strong>val</strong> responseValue = ResponseValue(posts)<br>                useCaseCallback?.onSuccess(responseValue)<br>            }<br>            <strong>override</strong> <strong>fun</strong> <strong>onError</strong>(t: <strong>Throwable</strong>) {<br>                <em>// Never use generic exceptions. Create proper exceptions. Since</em><br>                <em>// our use case is different we will go with generic throwable</em><br>                useCaseCallback?.onError(Throwable(&quot;Data not found&quot;))<br>            }<br>        })<br>    }<br>    <strong>class</strong> <strong>RequestValues</strong>(<strong>val</strong> userId: Int) : UseCase.RequestValues<br>    <strong>class</strong> <strong>ResponseValue</strong>(<strong>val</strong> posts: List&lt;Post&gt;) : UseCase.ResponseValue<br>}</pre><p><strong>The purpose of the </strong>UseCase<strong>s is to be a mediator between your </strong>ViewModel<strong>s and </strong>Repository<strong>s.</strong></p><p>Let’s say in the future you decide to add an “edit post” feature. All you have to do is add a new EditPost UseCase and all its code will be completely separate and decoupled from other UseCases. <strong>We’ve all seen it many times: New features are introduced and they inadvertently break something in preexisting code.</strong> Creating a separate UseCase helps immensely in avoiding that.</p><p>Of course, you can’t eliminate that possibility 100 percent, but you sure can minimize it. This is what separates Clean Architecture from other patterns: The code is so decoupled that you can treat every layer as a black box.</p><h3>The Data Layer</h3><p>This has all the repositories which the domain layer can use. This layer exposes a data source API to outside classes:</p><pre><strong>interface</strong> <strong>PostDataSource</strong> {</pre><pre>    <strong>interface</strong> <strong>LoadPostsCallback</strong> {<br>        <strong>fun</strong> <strong>onPostsLoaded</strong>(posts: <strong>List</strong>&lt;<strong>Post</strong>&gt;)<br>        <strong>fun</strong> <strong>onError</strong>(t: <strong>Throwable</strong>)<br>    }</pre><pre>    <strong>interface</strong> <strong>SaveTaskCallback</strong> {<br>        <strong>fun</strong> <strong>onSaveSuccess</strong>()<br>        <strong>fun</strong> <strong>onError</strong>(t: <strong>Throwable</strong>)<br>    }</pre><pre>    <strong>fun</strong> <strong>getPosts</strong>(userId: <strong>Int</strong>, callback: <strong>LoadPostsCallback</strong>)<br>    <strong>fun</strong> <strong>savePost</strong>(post: <strong>Post</strong>)<br>}</pre><p>PostDataRepository implements PostDataSource. It decides whether we fetch data from a local database or a remote server.</p><pre><strong>class</strong> <strong>PostDataRepository</strong> <strong>private</strong> <strong>constructor</strong>(<br>        <strong>private</strong> <strong>val</strong> localDataSource: PostDataSource,<br>        <strong>private</strong> <strong>val</strong> remoteDataSource: PostDataSource): PostDataSource {</pre><pre>    <strong>companion</strong> <strong>object</strong> {<br>        <strong>private</strong> <strong>var</strong> INSTANCE: PostDataRepository? = null<br>        <strong>fun</strong> <strong>getInstance</strong>(localDataSource: <strong>PostDataSource</strong>,<br>        remoteDataSource: <strong>PostDataSource</strong>): PostDataRepository {<br>            <strong>if</strong> (INSTANCE == null) {<br>                INSTANCE = PostDataRepository(localDataSource, remoteDataSource)<br>            }<br>            <strong>return</strong> INSTANCE!!<br>        }<br>    }<br>    <strong>var</strong> isCacheDirty = false<br>    <strong>override</strong> <strong>fun</strong> <strong>getPosts</strong>(userId: <strong>Int</strong>, callback: <strong>PostDataSource</strong>.<strong>LoadPostsCallback</strong>) {<br>        <strong>if</strong> (isCacheDirty) {<br>            getPostsFromServer(userId, callback)<br>        } <strong>else</strong> {<br>            localDataSource.getPosts(userId, <strong>object</strong> : PostDataSource.LoadPostsCallback {<br>                <strong>override</strong> <strong>fun</strong> <strong>onPostsLoaded</strong>(posts: <strong>List</strong>&lt;<strong>Post</strong>&gt;) {<br>                    refreshCache()<br>                    callback.onPostsLoaded(posts)<br>                }<br>                <strong>override</strong> <strong>fun</strong> <strong>onError</strong>(t: <strong>Throwable</strong>) {<br>                    getPostsFromServer(userId, callback)<br>                }<br>            })<br>        }<br>    }<br>    <strong>override</strong> <strong>fun</strong> <strong>savePost</strong>(post: <strong>Post</strong>) {<br>        localDataSource.savePost(post)<br>        remoteDataSource.savePost(post)<br>    }<br>    <strong>private</strong> <strong>fun</strong> <strong>getPostsFromServer</strong>(userId: <strong>Int</strong>, callback: <strong>PostDataSource</strong>.<strong>LoadPostsCallback</strong>) {<br>        remoteDataSource.getPosts(userId, <strong>object</strong> : PostDataSource.LoadPostsCallback {<br>            <strong>override</strong> <strong>fun</strong> <strong>onPostsLoaded</strong>(posts: <strong>List</strong>&lt;<strong>Post</strong>&gt;) {<br>                refreshCache()<br>                refreshLocalDataSource(posts)<br>                callback.onPostsLoaded(posts)<br>            }<br>            <strong>override</strong> <strong>fun</strong> <strong>onError</strong>(t: <strong>Throwable</strong>) {<br>                callback.onError(t)<br>            }<br>        })<br>    }<br>    <strong>private</strong> <strong>fun</strong> <strong>refreshLocalDataSource</strong>(posts: <strong>List</strong>&lt;<strong>Post</strong>&gt;) {<br>        posts.forEach {<br>            localDataSource.savePost(it)<br>        }<br>    }<br>    <strong>private</strong> <strong>fun</strong> <strong>refreshCache</strong>() {<br>        isCacheDirty = false<br>    }<br>}</pre><p>The code is mostly self-explanatory. This class has two variables, localDataSource and remoteDataSource. Their type is PostDataSource, so we don’t care how they are actually implemented under the hood.</p><p>In my personal experience, this architecture has proved to be invaluable. In one of my apps, I started with Firebase on the back end which is great for quickly building your app. I knew eventually I’d have to shift to my own server.</p><p>When I did, <strong>all I had to do was change the implementation in </strong>RemoteDataSource<strong>. I didn’t have to touch any other class even after such a huge change.</strong> That is the advantage of decoupled code. Changing any given class shouldn’t affect other parts of your code.</p><p>Some of the extra classes we have are:</p><pre><strong>interface</strong> <strong>UseCaseScheduler</strong> {</pre><pre>    <strong>fun</strong> <strong>execute</strong>(runnable: <strong>Runnable</strong>)</pre><pre>    <strong>fun</strong> <strong>&lt;V : UseCase.ResponseValue&gt;</strong> <strong>notifyResponse</strong>(response: <strong>V</strong>,<br>                                                   useCaseCallback: <strong>UseCase</strong>.<strong>UseCaseCallback</strong>&lt;<strong>V</strong>&gt;)</pre><pre>    <strong>fun</strong> <strong>&lt;V : UseCase.ResponseValue&gt;</strong> <strong>onError</strong>(<br>            useCaseCallback: <strong>UseCase</strong>.<strong>UseCaseCallback</strong>&lt;<strong>V</strong>&gt;, t: <strong>Throwable</strong>)<br>}<br></pre><pre><strong>class</strong> <strong>UseCaseThreadPoolScheduler</strong> : <strong>UseCaseScheduler {</strong></pre><pre>    <strong>val</strong> POOL_SIZE = 2</pre><pre>    <strong>val</strong> MAX_POOL_SIZE = 4</pre><pre>    <strong>val</strong> TIMEOUT = 30</pre><pre>    <strong>private</strong> <strong>val</strong> mHandler = Handler()</pre><pre>    <strong>internal</strong> <strong>var</strong> mThreadPoolExecutor: ThreadPoolExecutor</pre><pre>    <strong>init</strong> {<br>        mThreadPoolExecutor = ThreadPoolExecutor(POOL_SIZE, MAX_POOL_SIZE, TIMEOUT.toLong(),<br>                TimeUnit.SECONDS, ArrayBlockingQueue(POOL_SIZE))<br>    }</pre><pre>    <strong>override</strong> <strong>fun</strong> <strong>execute</strong>(runnable: <strong>Runnable</strong>) {<br>        mThreadPoolExecutor.execute(runnable)<br>    }</pre><pre>    <strong>override</strong> <strong>fun</strong> <strong>&lt;V : UseCase.ResponseValue&gt;</strong> <strong>notifyResponse</strong>(response: <strong>V</strong>,<br>                                                   useCaseCallback: <strong>UseCase</strong>.<strong>UseCaseCallback</strong>&lt;<strong>V</strong>&gt;) {<br>        mHandler.post { useCaseCallback.onSuccess(response) }<br>    }</pre><pre>    <strong>override</strong> <strong>fun</strong> <strong>&lt;V : UseCase.ResponseValue&gt;</strong> <strong>onError</strong>(<br>            useCaseCallback: <strong>UseCase</strong>.<strong>UseCaseCallback</strong>&lt;<strong>V</strong>&gt;, t: <strong>Throwable</strong>) {<br>        mHandler.post { useCaseCallback.onError(t) }<br>    }</pre><pre>}</pre><p>UseCaseThreadPoolScheduler is responsible for executing tasks asynchronously using ThreadPoolExecuter.</p><pre><strong>class</strong> <strong>ViewModelFactory</strong> : <strong>ViewModelProvider.Factory {</strong><br></pre><pre>    <strong>override</strong> <strong>fun</strong> <strong>&lt;T : ViewModel&gt;</strong> <strong>create</strong>(modelClass: <strong>Class</strong>&lt;<strong>T</strong>&gt;): T {<br>        <strong>if</strong> (modelClass == PostListViewModel::<strong>class</strong>.<strong>java</strong>) {<br>            <strong>return</strong> PostListViewModel(<br>                    Injection.provideUseCaseHandler()<br>                    , Injection.provideGetPosts(), Injection.provideSavePost()) <strong>as</strong> T<br>        }<br>        <strong>throw</strong> IllegalArgumentException(&quot;unknown model class $modelClass&quot;)<br>    }</pre><pre>    <strong>companion</strong> <strong>object</strong> {<br>        <strong>private</strong> <strong>var</strong> INSTANCE: ViewModelFactory? = null<br>        <strong>fun</strong> <strong>getInstance</strong>(): ViewModelFactory {<br>            <strong>if</strong> (INSTANCE == null) {<br>                INSTANCE = ViewModelFactory()<br>            }<br>            <strong>return</strong> INSTANCE!!<br>        }<br>    }<br>}</pre><p>This is our ViewModelFactory. You have to create this to pass arguments in your ViewModel constructor.</p><h3>Dependency Injection</h3><p>I’ll explain dependency injection with an example. If you look at our PostDataRepository class, it has two dependencies, LocalDataSource and RemoteDataSource. We use the Injection class to provide these dependencies to the PostDataRepository class.</p><p>Injecting dependency has two main advantages. One is that you get to control the instantiation of objects from a central place instead of spreading it across the whole codebase. Another is that this will help us write unit tests for PostDataRepository because now we can just pass mocked versions of LocalDataSource and RemoteDataSource to the PostDataRepository constructor instead of actual values.</p><pre><strong>object</strong> Injection {</pre><pre>    <strong>fun</strong> <strong>providePostDataRepository</strong>(): PostDataRepository {<br>        <strong>return</strong> PostDataRepository.getInstance(provideLocalDataSource(), provideRemoteDataSource())<br>    }</pre><pre>    <strong>fun</strong> <strong>provideViewModelFactory</strong>() = ViewModelFactory.getInstance()</pre><pre>    <strong>fun</strong> <strong>provideLocalDataSource</strong>(): PostDataSource = LocalDataSource.getInstance()</pre><pre>    <strong>fun</strong> <strong>provideRemoteDataSource</strong>(): PostDataSource = RemoteDataSource.getInstance()</pre><pre>    <strong>fun</strong> <strong>provideGetPosts</strong>() = GetPosts(providePostDataRepository())</pre><pre>    <strong>fun</strong> <strong>provideSavePost</strong>() = SavePost(providePostDataRepository())</pre><pre>    <strong>fun</strong> <strong>provideUseCaseHandler</strong>() = UseCaseHandler.getInstance()<br>}</pre><p>Note: I prefer using Dagger 2 for dependency injection in complex projects. But with its extremely steep learning curve, it’s beyond the scope of this article. So if you’re interested in going deeper, I highly recommend <a href="https://medium.com/@harivigneshjayapalan/dagger-2-for-android-beginners-dagger-2-part-i-f2de5564ab25">Hari Vignesh Jayapalan’s introduction to Dagger 2</a>.</p><h3>MVVM with Clean Architecture: A Solid Combination</h3><p>Our purpose with this project was to understand MVVM with Clean Architecture, so we skipped over a few things that you can try to improve it further:</p><ol><li>Use LiveData or RxJava to remove callbacks and make it a little neater.</li><li>Use states to represent your UI. (For that, check out <a href="https://youtu.be/0IKHxjkgop4">this amazing talk by Jake Wharton</a>.)</li><li>Use Dagger 2 to inject dependencies.</li></ol><p>This is one of the best and most scalable architectures for Android apps. I hope you enjoyed this article, and I look forward to hearing how you’ve used this approach in your own apps!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d3a1f9fd473" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is PHP?]]></title>
            <link>https://medium.com/@uferesamuel/what-is-php-68a2b3e4c716?source=rss-a688fa2cf1f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/68a2b3e4c716</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ufere Samuel]]></dc:creator>
            <pubDate>Tue, 28 May 2019 11:20:07 GMT</pubDate>
            <atom:updated>2019-05-28T11:20:07.417Z</atom:updated>
            <content:encoded><![CDATA[<p>What is PHP?<br>PHP started out as a (relatively) simple server-side scripting language called Personal Home Page, developed by Rasmus Lerdorf. It has grown to a full-fledged programming language supported by scores of open-source developers. At the same time, the meaning of &quot;PHP&quot; has morphed from Personal Home Page to the somewhat recursive PHP Hypertext Processor. You can find the official PHP Web page at http://www.php.net.</p><p>Although PHP runs on many platforms, it is integrated into the Apache Web server, so PHP and Apache make a powerful combination. PHP works with many database management systems. We will be using PostgreSQL in our examples, but PHP also works with the other major open source database, MySQL. You can combine Apache and PHP with an open-source database management system to provide a complete database-driven Web server platform. The software cost of such a system is zero.</p><p>Hello, World!<br>PHP programs look a lot like HTML pages. In fact, they are HTML pages with programming mixed in. Blocks of PHP code are enclosed in XML processing instruction marks. (There are actually several ways to do this, but the XML approach is the one that&#39;s future-proof.) Here is the HelloWorld program in PHP:</p><p>&lt;html&gt;<br>&lt;head&gt;<br>&lt;title&gt;Hello, World!&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>&lt;?php echo &#39;&lt;h1&gt;Hello, World!&lt;/h1&gt;&#39;;<br> echo &#39;&lt;p&gt;Hello, world!&lt;/p&gt;&#39;;<br>?&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br>This program would be stored in a file with a .php extension and located on the server in an &quot;ordinary&quot; HTML directory. From this simple example we learn several things, most of which are repeated from above for the sake of getting them into a neat list:</p><p>PHP programs are HTML files...<br>... with embedded PHP statements...<br>... enclosed in XML processing instruction marks<br>Each PHP statement ends with a semicolon<br>PHP output is sent to the client browser<br>The HTML part of the program is copied unchanged to the client browser<br>The PHP code is interpreted where it is encountered in the document.<br>The last two statements may need a little more explanation. The .php file extension alerts the Web server program to hand the file off to the PHP processor. The PHP processor has two modes, copy and interpret. The processor starts off in copy mode; text from the file, presumably HTML, is copied to the network connection and sent to the client browser. When a &lt;?php processing instruction is encountered the processor switches to interpret mode. The PHP statements are interpreted, and their output, if any, is sent to the browser. The processor remains in interpret mode until a ?&gt; is encountered, which switches it back to copy mode.</p><p>You won&#39;t remember this when you need it, but I&#39;m going to tell you anyway so I can say, &quot;I told you so!&quot; later. PHP has functions that can manipulate the HTTP headers. However, as soon as anything is sent to the Web server, the headers are generated and sent. After that, the header functions are invalid. Even a blank line before the first &lt;?php will cause the headers to be generated. (Because the PHP processor starts off in copy mode, that&#39;s why!)</p><p>PHP Variables<br>PHP variable names start with a dollar sign. The first character after the dollar sign must be a letter or underscore, which may be followed by any number of letters, digits or underscores. PHP variable names are case sensitive.</p><p>PHP is dynamically typed; a variable is bound to a datatype when it is assigned, and a later assignment can change the datatype. PHP has four scalar, two special and two compound datatypes:</p><p>Boolean<br>integer<br>double<br>string<br>NULL<br>resource<br>array<br>object<br>Boolean variables have the values TRUE and FALSE. The exact format of the integer datatype is implementation-dependent, but integers are generally 32-bit numbers. Doubles are floating-point numbers; their representation may include a decimal point and optionally an exponent. The exponent is indicated by e or E and a signed integer. Strings are sequences of ASCII-8 characters of (practically) unlimited length. A variable that has never been assigned has the special type and value NULL. We leave resource and array for later. The object datatype is beyond the scope of this tutorial.</p><p>Strings, Escapes, Interpolation and Output<br>PHP has two ways of representing string literals. A string literal enclosed in quotation marks (double quotes) receives special processing by PHP that will be discussed below. A string literal enclosed in apostrophes (single quotes) is taken by PHP exactly as it is written with the exception that you can include an apostrophe in such a string by escaping it with a backslash, like this:</p><p>$answer = &#39;You\&#39;re right!&#39;;<br>When a string is enclosed in double quotes, PHP processes escaped characters, such as \n for new line. Even more useful, it recognizes variables, formats them for readable output, and interpolates them into the string. This makes it very easy to generate output that&#39;s a combination of literals and variables:</p><p>$answer=42;<br>echo &quot;The answer to everything is $answer.&quot;;<br>prints (sends to the browser):</p><p>The answer to everything is 42.</p><p>You can include a double-quote in a double-quoted string by escaping it with a backslash. The dollar sign can be escaped with a backslash to print a literal dollar sign rather than attempting variable interpolation.</p><p>$answer=42;<br>echo &quot;The answer to everything is \$answer.&quot;;<br>prints (sends to the browser):</p><p>The answer to everything is $answer.</p><p>Both kinds of strings may contain an embedded new line created by pressing the enter key, like this:</p><p>$myString = &#39;Here is a string with<br> an embedded new line.&#39;;<br>This isn&#39;t as useful as it might appear. If you output the string, the HTML parser in the browser will suppress the new line unless you are in the context of preformatted text, and it&#39;s hard to see what&#39;s going on when you read the program.</p><p>(There is a lot more to know about PHP strings. You can find a the official PHP documentation at http://www.php.net/manual/en/printwn/language.types.string.php#language.types.string.syntax.single. )</p><p>You generate output in PHP using the echo, print, or printf functions. The echo function is the most friendly of these. When used without parentheses, echo takes any number of parameters and copies them to the output stream. Variables given as parameters or enclosed within a double-quoted string are converted to a default output format that is usually what you will want. (If it isn&#39;t, you need printf.) Remember that the output is destined for a browser, so if you want formatting, you must emit HTML tags:</p><p>echo &quot;The answer is&lt;br /&gt; $answer&lt;br /&gt;&quot;;<br>will produce two lines on the browser screen, one with &quot;The answer is&quot; and one with the contents of the variable $answer, then will continue output on a third line because of the trailing &lt;br /&gt;.</p><p>If you use echo( ) like a function, with parentheses, e.g. echo($answer); you can use only one parameter. Best to leave the parentheses off and treat echo like a keyword rather than a function.</p><p>The print( ) functionworks exactly like the echo( ) function, i.e. it takes exactly one operand and sends the operand to the client browser.</p><p>The printf( ) function works like its C counterpart, and is used when you need absolute control over the formatting of the output. For example, you might use printf to format a variable of type double as dollars and cents.</p><p>Operators and Functions<br>PHP has the usual arithmetic operators, +, -, * and /. The division operator always returns a double (floating point) type, even if the result is an integer. You can use the intval() function to convert this back to an integer. There is also a modulus operator, %, that returns the remainder after division.</p><p>There are increment and decrement operators, ++ and --. These can be used for both post-increment and pre-increment, as in C.</p><p>The assignment operator is =. It can be combined with the binary (two-operand) arithmetic operators and string operators. So, the following are equivalent:</p><p>$a=$a+$b;<br>$a+=$b;<br>PHP implements comparison operators = = for equality, &lt; and &gt; for less than and greater than, &lt;= and &gt;= for less than or equal and greater than or equal. Inequality may be represented by &lt; &gt; or !=.</p><p>The period (.) is the string concatenation operator.</p><p>There is much more to learn about PHP operators. You can find what you need to know at http://www.php.net/manual/en/language.operators.php.</p><p>PHP has more functions than you will ever use in a lifetime. If it can be done, there&#39;s a PHP function to do it. You will want to browse the list of available functions at http://www.php.net/manual/en/funcref.php paying particular attention to the following:</p><p>Math functions<br>String functions<br>Date and time functions<br>PostgreSQL functions<br>An hour or so browsing in the function list will amaze you at the breadth of things you can do with PHP.</p><p>Language Structure and Control Statements<br>PHP statements may be grouped into blocks by enclosing them in curly braces, { }.</p><p>The if statement implements the selection construct. There is an optional else part.</p><p>if ($a &gt; $b)<br> echo &quot;A is greater than B&quot;;<br>else<br> echo &quot;A isn&#39;t greater than B (might be equal).&quot;;<br>Both if and else can take a block of statements enclosed in curly braces.</p><p>A case-like selection construct can be implemented with if and elseif. An alternative is the switch statement.</p><p>Counter-controlled iteration is implemented with for loops:</p><p>for ($i = 1; $i &lt;= 10; $i++) {<br> echo $i;<br>}<br>A more general iteration control structure is while. We use a counter in the example below, but any expression can be used to control a while loop.</p><p>$i = 1;<br>while ($i &lt;= 10) {<br> echo $i;<br> $i++;<br>}<br>The while loop is a pretest loop; the conditional expression is checked before the body of the loop is executed. PHP implements the posttest loop with do-while.</p><p>$i = 0;<br>do {<br> echo $i;<br>} while ($i&gt;0);<br>The value of $i (zero) will be printed exactly one time because the continuation condition ($i&gt;0) is false at the beginning. The body of a posttest loop is always executed at least once.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68a2b3e4c716" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Fix WordPress Posts Returning 404 Error]]></title>
            <link>https://medium.com/@uferesamuel/how-to-fix-wordpress-posts-returning-404-error-d8c6554f1d79?source=rss-a688fa2cf1f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8c6554f1d79</guid>
            <category><![CDATA[cms]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[wordpress]]></category>
            <dc:creator><![CDATA[Ufere Samuel]]></dc:creator>
            <pubDate>Tue, 16 Apr 2019 21:17:30 GMT</pubDate>
            <atom:updated>2019-04-16T21:17:30.497Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hello guys i want to show us a very simple something but i learnt it the hard way…</h3><p>WordPress is a powerful CMS. Sometimes a slight tweak can make your website inaccessible. However, finding a solution for any WordPress problem is extremely easy. A common problem that most WordPress users face at some point is WordPress posts returning a 404 Error. In this article we will show you how to fix WordPress posts returning 404 error.</p><p>Usually in this scenario a user can access their WordPress admin area, their blog’s main page, but when accessing a single posts they get a <strong>404 Not found</strong> error. First of all, don’t panic most of the time your posts are still there and completely safe. This usually happens if your .htaccess file got deleted or something went wrong with the rewrite rules. What you need to do is fix your permalinks settings.</p><p>Go to <strong>Settings » Permalinks</strong>, and simply click on <em>Save Changes</em> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8_94VcdrBhe8lMwS30ysvw.png" /></figure><p>This will update your permalinks settings and flush rewrite rules. In most cases this solution fixes the WordPress posts 404 error. However, if it does not work for you, then you probably need to update your .htaccess file manually.</p><p>Login to your server using FTP, and modify the <a href="https://www.wpbeginner.com/glossary/htaccess/">.htaccess file</a> which is located in the same location where folders like /wp-content/ and /wp-includes/ are located. The easiest thing you can do is to temporarily make the file writeable by changing the permissions to 666. Then repeat the original solution. Don’t forget to change the permissions back to 660. You can also manually add this code in your .htaccess file:</p><p># BEGIN WordPress</p><p>&lt;IfModule mod_rewrite.c&gt;</p><p>RewriteEngine On</p><p>RewriteBase /</p><p>RewriteRule ^index\.php$ - [L]</p><p>RewriteCond %{REQUEST_FILENAME} !-f</p><p>RewriteCond %{REQUEST_FILENAME} !-d</p><p>RewriteRule . /index.php [L]</p><p>&lt;/IfModule&gt;</p><p># END WordPress</p><p>We hope this article helped you resolve posts returning 404 error in WordPress.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8c6554f1d79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UML Class Diagrams The simple Approach]]></title>
            <link>https://medium.com/@uferesamuel/uml-class-diagrams-the-simple-approach-eee2d1ffc125?source=rss-a688fa2cf1f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/eee2d1ffc125</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Ufere Samuel]]></dc:creator>
            <pubDate>Thu, 27 Sep 2018 19:32:03 GMT</pubDate>
            <atom:updated>2018-09-27T19:32:03.970Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a short tutorial on UML Class Diagrams. We’ll discuss what they are, why they’re needed, some technical stuff, and then we’ll dive into an example.</p><h3>What is a Class Diagram?</h3><p>Suppose you have to design a system. Before implementating a bunch of classes, you’ll want to have a conceptual understanding of the system — that is, what classes do I need? What functionality and information will these classes have? How do they interact with one another? Who can see these classes? And so on.</p><p>That’s where class diagrams come in. Class diagrams are a neat way of visualizing the classes in your system<em> before</em> you actually start coding them up. They’re a static representation of your system structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TYRSuON0vVxy8olllrBVEw.png" /><figcaption>Example of a Class Diagram for a Banking System</figcaption></figure><p>This is a fairly simple diagram. However, as your system scales and grows, it becomes increasingly difficult to keep track of all these relationships. Having a precise, organized, and straight-forward diagram to do that for you is integral to the success of your system.</p><h3>Why do we need class diagrams?</h3><ol><li>Planning and modeling ahead of time make programming much easier.</li><li>Besides that, making changes to class diagrams is easy, whereas coding differnent functionality after the fact is kind of annoying.</li><li>When someone wants to build a house, they don’t just grab a hammer and get to work. They need to have a blueprint — a design plan — so they can ANALYZE &amp; modify their system.</li><li>You don’t need much technical/language-specific knowledge to understand it.</li></ol><h3>Some Technical Stuff</h3><h4>Class Representation in UML</h4><p>A class is represented as a box with 3 compartments. The uppermost one contains the class name. The middle one contains the class attributes and the last one contains the class methods. Like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*vY53qi20_IryBWOBDnCHpg.png" /></figure><p>They adhere to the following convention:</p><p>attribute name : type</p><p>method name (parameter: type)</p><ul><li>if you’d like to set a default value to an attribute do as above balance : Dollars = 0</li><li>if a method doesn’t take any parameters then leave the parentheses empty. Ex: checkBalance()</li></ul><h4>Visibility of Class Members</h4><p>Class members (attributes and methods) have a specific visibility assigned to them. See table below for how to represent them in UML.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*cjxQc8YklOZGQNeCQVmGkg.png" /><figcaption>visibility and how to denote it</figcaption></figure><p>Let’s specifiy the visibility of the members of the BankAccount class above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*TPgpSIX9iP8L9yYHH6CRfA.png" /></figure><p>We made the `owner` and balance private as well as the withdraw<em> </em>method. But we kept the deposit method public. (Anyone can put money in, but not everyone can take money out. Just as we like it.)</p><h3>Relationships</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*EUvDMA1vr0DiucONPzK9kA.png" /><figcaption>Summary of types of relationships and their notation</figcaption></figure><h4>Association</h4><p>a relationship between two separate classes. It joins two entirely separate entities. There are four different types of association: bi-directional, uni-directional, aggregation (includes composition aggregation) and reflexive. Bi-directional and uni-directional associations are the most common ones.</p><p>This can be specified using multiplicity (one to one, one to many, many to many, etc.).</p><p>A typical implementation in Java is through the use of an instance field. The relationship can be bi-directional with each class holding a reference to the other.</p><h4>Inheritance</h4><p>indicates that child (subclass) is considered to be a specialized form of the parent (super class). For example consider the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*szU8ngrWSXmBNPYReMyK5w.png" /></figure><p>Above we have an animal parent class with all public member fields. You can see the arrows originating from the duck, fish, and zebra child classes which indicate they inherit all the members from the animal class. Not only that, but they also implement their own unique member fields. You can see that the duck class has a swim() method as well as a quack() method.</p><h4>Realization/Implementation</h4><p>a relationship between two model elements, in which one model element implements/executes the behavior that the other model element specifies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IqO6TgyLWJ1g9VthkB37sA.png" /><figcaption>example of implements</figcaption></figure><h4>Dependency</h4><h4>Aggregation</h4><p>a special form of association which is a unidirectional (a.k.a one way) relationship between classes. The best way to understand this relationship is to call it a “has a” or “is part of” relationship. For example, consider the two classes: Wallet and Money. A wallet “has” money. But money doesn’t neccessarily need to have a wallet so it’s a one directional relationship.</p><h4>Composition</h4><p>a restricted form of Aggregation in which two entities (or you can say classes) are highly dependent on each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*rKhbe3lwRvfHKi-VTY_9xQ.png" /></figure><p>A human needs a heart to live and a heart needs a human body to function on. In other words when the classes (entities) are dependent on each other and their life span are same (if one dies then another one too) then its a composition.</p><h4>Multiplicity</h4><p>after specificyfing the type of association relationship by connecting the classes, you can also declare the cardinality between the associated entities. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NZMShZQ7NenJzAAL96ibPg.png" /></figure><p>The above UML diagram shows that a house has exactly one kitchen, exactly one bath, atleast one bedroom (can have many), exactly one mailbox, and at most one mortgage (zero or one).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hX9J6JvZdA1kSoq2V0LjNA.png" /></figure><h3>UML CLASS DIAGRAM EXAMPLE</h3><p>Now, let’s take what we’ve learned in the example above and apply it. In this example we are asked to create a class diagram for a banking system. It must have the following classes:</p><ul><li>Bank</li><li>ATM</li><li>Customer</li><li>Account</li><li>Transaction</li><li>Checking Account</li><li>Savings Account</li></ul><p>Let’s determine possible class members for each of the above.</p><p>The bank class represents a physical bank. It has a location and a unique id. This bank also manages several accounts. **There’s an association!** What type of association is this? Is a bank entirely composed of accounts (composition)? Or are accounts ‘part of’ a bank (aggregation)? It looks like aggregation. It can’t be composition because that would mean that both classes live and die together. That’s not quite right because you can have a bank without accounts and you can have accounts without a bank. We’ll add a method called getAccounts().</p><p>The ATM class represents a physical ATM. Right off the bat, we can come up with three methods for the ATM: withdraw(), deposit(), checkBalance(). Each of these methods takes the card number as input. In terms of attributes, an ATM has a location and is managed by a specific bank.</p><p>The customer class represents a real customer. This customer has a name, address, date of birth (dob), card number, and pin. For this person to be considered a customer, they must have an account. **There’s another association!** This isn’t aggregation or composition, it’s just a bi-directional association (drawn using a blank line no arrows).</p><p>The account class represents a bank account. Common attributes of bank accounts include account number, balance, etc. You can deposit() withdraw() money from the account. In addition, banks might offer two types of accounts: a checking account and a savings account. These two can thus be considered child classes of the account class and can inherit from it too. We’ll denote this by using a solid black line with an unfilled arrow going into the account class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Srh6QviwDT6LFFdSnyzelA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eee2d1ffc125" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Structures for Newbies…]]></title>
            <link>https://medium.com/@uferesamuel/data-structures-for-newbies-95ae628fc34c?source=rss-a688fa2cf1f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/95ae628fc34c</guid>
            <category><![CDATA[newbie]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Ufere Samuel]]></dc:creator>
            <pubDate>Mon, 24 Sep 2018 23:29:29 GMT</pubDate>
            <atom:updated>2018-09-24T23:29:29.270Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>What is data structure?</strong></p><p>The common question on the lips of newbies to computer science or software engineering who have signed up to Data structures class is always: <br>“What the heck is data structure?”</p><p>The simplest way to answer their question is by describing data structures as a way of organizing and storing data so that operations can be performed efficiently. This leads us to the question, what kind of operations are we talking about? Accessing, inserting, deleting, finding, and sorting the data are some of the basic operations that one can perform using data structures. Not all data structures can perform these operations efficiently, that’s what led to the development of different data structures. Let’s say you are to find a specific book in an unorganized library, that task would take an enormous amount of time. Just like a library organizes their books, we need to organize our data so that operations can be performed efficiently.</p><p>If you have previous experience with programming, you might know what a pre-defined data type is. A pre-defined data type such as Integer, Strings, Boolean is used to create the structure of data. The use of data type is based on the user requirement and the kind of data they want to store. Now let’s dive into the data structures that are used in our day to day programming, and we will also look into the support for the data structures for different programming languages.</p><h3>One Dimensional Arrays</h3><p>A basic data structure which one uses in a day to day programming is an array. An array can hold a fixed number of containers to store data and operations could be performed on that data according to the user’s needs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*pscP-dh0pfgbR9IaCgNXqQ.png" /></figure><p>In the picture above, an array is defined with the name <em>arrayName</em> and has an integer data type. The number below in the bold shows the memory address each container of an array is assigned to. The important thing here to remember is an array index always starts at 0 and ends at (total array size -1). So, let’s just say you defined an array of length 5, <em>arrayName[5]</em>, then the indexes of this array would be<em> arrayName[0]</em>, <em>arrayName[1]</em>, <em>arrayName[2]</em>, <em>arrayName[3]</em>,<em> arrayName[4]</em>.</p><h3>Multidimensional Arrays</h3><p>A multidimensional array is just an extension of the normal array, where we define an array with a row of containers. In case of a multidimensional array, we have rows as well as columns. In order to access an index, we need two numbers to get there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*3xr9AK7euOlKCfZtVwRz2g.png" /></figure><p>In the picture above, we defined an <em>arrayName[3][4] </em>with 3 rows and 4 columns and in total of Row * Column (3*4) indexes. Multidimensional arrays are sometimes referred to as tables or matrix because of their structure.</p><h3>Dynamic Arrays</h3><p>Most of the programming languages allow you to define dynamic arrays, which means the memory is allocated during program execution. Consider it this way, you defined an array with 10 indexes but, you only need 3 indexes, thus the remaining 7 indexes are laid to waste, thereby consuming extra memory. Dynamic arrays give you the flexibility to allocate memory according to the program requirement.</p><h3>Support for Arrays for different programming languages:</h3><p>Java :- There are a couple of classes for arrays, but the best known one is <em>ArrayList</em> class.</p><p>C++ :- Vectors are used to represent the dynamic arrays in C++. It can be implemented using <em>std::vector</em>.</p><p>Python :- Python has a new data type known as <em>list</em> just like Boolean and Integers. The <em>list</em> data type can be used to dynamically define arrays.</p><h3>Singly Linked List</h3><p>A linked list is a collection of nodes that are connected by links. Linked list contains node which store the data items and the address to the next node. The first node is usually referred to as the head node and the last node is referred to as the tail node. The pointer of the head node points to the next node and the pointer of the tail node points to Null.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*tDb_6PNCfF7MND6-NzKh6Q.png" /></figure><p>The dynamics of this data structure makes it easier to add or remove nodes from the end. In order to add/remove a node, you just need to keep track of the previous node and the node after and adjust the pointers accordingly.</p><h3>Doubly Linked List</h3><p>A doubly linked list is not much different from a singly linked list, the only thing that sets them apart is the pointer to the previous node. The picture below can give you a brief idea of what the structure should look like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*4z6YxNMyUZ3Rh3LIWLEArA.png" /></figure><p>In the case of a doubly linked list, the previous pointer of the head node points to Null and the next pointer of the tail points to Null. The previous pointer makes it easier to traverse in either direction. So, node addition and removal become super easy, all you need to do is keep track of the previous node and the next node and adjust the pointer accordingly.</p><h3>Circular Linked List</h3><p>A circular linked list is a linked list where all the nodes are connected to form a circle. There is no head or tail node. The advantage of having this type of linked list is any node can be used as a starting point.</p><h3>Comparison Between Arrays and Linked List</h3><p>A list is a different type of data structure from an array. Instead of storing data in chunks of memory the array requires a contiguous memory space. If you add an element to an array, it might change the memory location of the entire array, but the data remains intact. An array gives you the index number, therefore, you can access it directly or sequentially. Whereas to access any data member you must traverse through the entire list.</p><h3>Support for Linked Lists for different programming languages:</h3><p>Java :- Java has an inbuilt class called <em>LinkedList</em> which can be used to implement a linked list.</p><p>C++ :- Like Java, C++ has also a Standard Template Library called <em>list </em>for linked list implementation.</p><p>Python :- Python also has an inbuilt module <em>llist</em> which implements linked lists.</p><h3>Stack</h3><p>You have probably heard this word in your day to day life, whether it is referring to a deck of cards or books lying on top of a desk. Well, the data structure works in a similar manner as you would perform actions on a real-world stack. For example, you can only add or remove books from the top of the stack.</p><p>A stack is a LIFO data structure which means Last In First Out, the last item to come is the first one to go out. A stack can either be implemented using an array or a linked list. Consider a stack of books, the last book would obviously be placed at the top and if you want to remove a book you will remove one from the top. The three basic operations a stack could perform are:</p><p>· Push — to input data into stack and place it on top.</p><p>· Pop — to remove the data from the top.</p><p>· Peek — to look at the data at the top without removing it.</p><p>The picture below shows the effect of these operations on the structure</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*L8JYwFvrgPf1e7Mq32ONIg.png" /></figure><h3>Support for Linked Lists for different programming languages:</h3><p>Java :- Java has an inbuilt class called <em>Stack</em> which can be used to implement stack data structures.</p><p>C++ :- Like Java, C++ has also a Standard Template Library called <em>stack</em> for linked list implementation.</p><p>Python :- Python does not have an explicit stack class, but lists can be implemented as stacks.</p><h3>Queue</h3><p>Just like the word stack, the word queue is also derived from day to day activities. You have most likely seen a queue of people in a supermarket at the billing counter where the last one to come stands at the end and the first one to come is the first one to get their groceries check out. In the similar manner, queue works where the operations are performed at both ends.</p><p>A stack is a FIFO data structure which elaborates to First In First Out. A queue, like stack, can either be implemented using arrays or linked list. The three most commonly performed operations on queue are:</p><p>· enqueue — to input data into stack and place them at the bottom.</p><p>· dequeue — to remove the data from the top.</p><p>· Peek — to look at the data at the top without removing it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*DW1Oku8KUde6a-kYVPNU-w.png" /></figure><h3>Support for Linked Lists for different programming languages:</h3><p>Java :- Queue can be implemented using <em>List</em> class in Java</p><p>C++ :- Like Java, C++ has also a Standard Template Library called <em>Queue </em>for queue implementation.</p><p>Python :- The<em> queue</em> module in python offers the functionality of the <em>queue </em>class. Since queues can be implemented using linked list therefore, <em>llist</em> can also be used.</p><h3>Trees</h3><p>The tree data structure resembles an upside tree, at the top we have a root node which is divided into a left and a right node. They have links between them, which connect all the nodes. Unlike linked list where a node can be connected to only one node, a tree could have a node connected to two or more nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*3sCSV0su_xNOc0oXOjying.png" /></figure><h3>Binary Trees</h3><p>Binary trees are special kind of trees where the left node is always smaller than the parent node and the right node is always bigger than the parent node. In order to add/delete a node we have to compare the value with the root node and then traverse to a specific point to insert/delete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*A_8-mxZ4na-q0DHcNQ3FsA.png" /></figure><h3>Support for Linked Lists for different programming languages</h3><p>Java :- Java doesn’t have any built-in class to implement tree data structure.</p><p>C++ :- Just like Java, C++ also doesn’t have any container in standard template library to implement trees.</p><p>Python :- Python doesn’t have built-in data structures so in order to implement a tree you have to create the structure manually.</p><h3>Conclusion</h3><p>There are some points you need to consider while deciding which data structure satisfies your need. Unless you have a really big set of data, it doesn’t matter which data structure you use. The questions you need to ask yourself before implementing a data structure is:</p><ul><li>How much data you need to store?</li><li>How often do you access data?</li><li>What is the purpose of the data? Do you need to access, insert, delete, or sort the data?</li></ul><p>The algorithms work differently with different data structures and across different programming languages, so you need to understand the respective syntax of the language before implementing a data structure.</p><p>This lecture was delivered at the ighubfellowship2018 by <a href="http://www.ighub.com.ng/">Innovation Growth Hub Aba, Abia State of Nigeria</a>…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95ae628fc34c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IGHUB Fellowship 2018]]></title>
            <link>https://medium.com/@uferesamuel/ighub-fellowship-2018-970f45dd5f40?source=rss-a688fa2cf1f7------2</link>
            <guid isPermaLink="false">https://medium.com/p/970f45dd5f40</guid>
            <category><![CDATA[design]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[wordpress-web-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Ufere Samuel]]></dc:creator>
            <pubDate>Tue, 11 Sep 2018 19:32:03 GMT</pubDate>
            <atom:updated>2018-09-11T19:32:03.884Z</atom:updated>
            <content:encoded><![CDATA[<p>IGHUB Fellowship 2018</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*z8-5D7hN4HUjT62UH31_4w.jpeg" /></figure><p>One of the greatest lies I was told while growing up was “Go to school, be a good student, graduate with good grades and you will get a good and well-paying job”. I don’t blame my parents for telling me that anyway, what do you expect from a parent who grew up in an era where people were respected and given titles and important positions in the clan for attaining “commercial school” certificate?</p><p>But things change, more rapidly than some persons care enough to admit. Facts have shown that there has been a 150% paradigm shift towards technology since the 1990&#39;s.</p><p>It is therefore very crystal clear that anybody who is not tech-driven will soon be left behind in his medieval world.</p><p>The day I learnt a bitter lesson about the reality of life was when i came across a guy who never saw the four-walls of a higher institution (I am not in any way discrediting the value of higher education, my degree is up my sleeves). This tech-whiz flew from country to country as a database specialist.</p><p>Sure, I was impressed, but more curious even.</p><p>He told me something that revolutionized my thinking forever “Sam, life don’t answer to CERTIFICATE but to SABIFICATE”. It was then it dawned on me that if I’d given 20% of school time, of the times I spent in school pursuing abstract knowledge, of the times I used to forcefully learn topics I had absolutely no interests, If I had channeled 20% of that whole time pursuing ‘real’ knowledge, technical-know-how, I bet I would have been miles away from my current spot.</p><p>My quest for knowledge drove me to several places (NIIT, HIIT, AfriHub) but i couldn’t afford their fees as the cheapest course i saw was 150k (Introduction to HTML), I resorted to self-development and shortly after my NYSC i was privileged to be among the first set of fellows of software engineering at nHub Nigeria…</p><p>Guys I’m telling you my story because I acquired knowledge the hard and expensive way, through nooks and crooks. But everyone mustn’t have same story as mine.</p><p>There’s an opportunity coming your way on a platter of gold, take advantage of it, grab it.</p><p>Apply to IGHUB netprenureship and Developers fellowship… IT IS FREE (This is part of a Niger Delta Youth Employment Pathway Project Supported by PIND), you only have to find yourself in or within Aba for a space of 3 months (The city has its magic, you may never want to leave).</p><p>It’s not too great a price to pay for your future, I once shut down my life for 1 year to relocate to Jos plateau state where i knew nobody just to gain knowledge)</p><p>Registration ends on 15th Sep. and classes commences on 17th Sep, apply online on bit.ly/IGHUBFELLOWSHIP2018</p><p>Training includes:</p><p>Software Development</p><p>- Front End Development</p><p>- Back End Development</p><p>- Mobile App Development</p><p>Netpreneurship</p><p>- Social media marketing certification</p><p>- Email marketing certification</p><p>- Digital advertising mastery certification</p><p>- E-commerce marketing course</p><p>- Online product launch and activation specialist</p><p>- Info marketing professional</p><p>- Mini-importation for Netpreneurs</p><p>- Mobile Marketing for Professionals</p><p>- Professional Blogging Certification</p><p>- Wordpress Professional Certification</p><ul><li>Graphics Design</li></ul><p>Registration ends on 15th Sep. and classes commences on 17th Sep, apply online on</p><p>bit.ly/IGHUBFELLOWSHIP2018</p><p>www.ighub.com.ng</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=970f45dd5f40" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>